Re: Tidying code for PHP5.0.5/PHP4.4.0

From: Date: Tue, 20 Sep 2005 08:31:41 +0000
Subject: Re: Tidying code for PHP5.0.5/PHP4.4.0
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-222735@lists.php.net to get a copy of this message
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/

« previous php.general (#222735) next »