You are here: [please ignore!] Re: [PHP] [from internals] Re: ref fix revisited « PHP « IT news, forums, messages
[please ignore!] Re: [PHP] [from internals] Re: ref fix revisited

Posted by Jochem Maas on 09/13/05 11:20

Rasmus please ignore my last mail, I was being blind and stupid.

Jasper Bryant-Greene wrote:
> Jochem Maas wrote:
>
>> hello Rasmus,
>>
>> sorry to interrupt ... but ... could you possibly
>> spare a moment to explain why the SquirrelMail example you gave
>> is 'dumb' code? (I for one would like to avoid writing dumb code
>> wherever possible, and it looks a lot like I line I could have written!)
>>
>> many thanks and regards,
>> jochem
>>
>> Rasmus Lerdorf wrote:
>>
>> ...
>>
>>>
>>> SquirrelMail has code like this all over the place:
>>>
>>> $value = strtolower(array_shift(split('/\w/',trim($value))));
>>>
>
> I know I'm not Rasmus ... but I thought he already explained it pretty
> well in the email you quoted. By the way, please don't top-post.

only if Rasmus asks ;-)! normally I don't top-post but in this case I figured
I save Rasmus the effort of scrolling ... I figured he'd remember the gist
of a email he himself wrote less than a day ago...

>
> array_shift [1] receives its first argument as a reference (and modifies
> it), but because you're not actually passing a variable here, but
> actually the result of split(), what exactly is array_shift meant to
> modify?

ok it's too early I guess, I looked right past it - I was thinking to complex,
thanks for the heads up...

>
> A better way to write that would be:
>
> <?php
> $value_parts = split('/\w/', trim($value));
> $value = strtolower($value_parts[0]);
> ?>
>
> ... which has the advantage of being a bit more readable too.

debatable ... no bog deal either way ...

$value = split('/\w/', trim($value));
$value = strtolower($value[0]);

.... saves a var, no?

>
> [1] http://php.net/array_shift

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация