[please ignore!] Re: [PHP] [from internals] Re: ref fix revisited
| From: | Jochem Maas | Date: | Tue, 13 Sep 2005 08:20:39 +0000 |
| Subject: | [please ignore!] Re: [PHP] [from internals] Re: ref fix revisited | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-222256@lists.php.net to get a copy of this message | ||
Rasmus please ignore my last mail, I was being blind and stupid.
Jasper Bryant-Greene wrote:
Jochem Maas wrote: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...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: ...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.SquirrelMail has code like this all over the place: $value = strtolower(array_shift(split('/\w/',trim($value))));
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