Re: [from internals] Re: ref fix revisited

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

 



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.

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?

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.

[1] http://php.net/array_shift
--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
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