[please ignore!] Re: [PHP] [from internals] Re: ref fix revisited

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux