Lester Caine wrote:
I suppose the REAL questions was - "Why was using the function in this way a 'bad practice', is there any way that it could be made a 'good practice' since the intent is so obvious?" I understand the new checks, but I don't see that the original was particularly 'bad' - only that under some conditions it might cause a problem?


Basically, in PHP, a reference (such as what key() takes as a parameter [1]) can only point to an actual variable, not directly to the result of a function. So you have to assign the output of the function to a variable first.

From the PHP manual [2]:
| the following examples of passing by reference are invalid:
|
| foo(bar()); // Produces fatal error since PHP 5.1.0
| foo($a = 5); // Expression, not variable
| foo(5); // Produces fatal error

Whether this is the optimal behaviour has been the subject of recent debate on this list [3]. Rasmus states that the current behaviour of throwing a fatal error will be changed to a notice.

[1] http://php.net/key
[2] http://php.net/language.references.pass
[3] http://marc.theaimsgroup.com/?l=php-general&m=112689425109173&w=2
--
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

Reply via email to