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

From: Date: Tue, 20 Sep 2005 07:45:38 +0000
Subject: Re: Tidying code for PHP5.0.5/PHP4.4.0
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-222732@lists.php.net to get a copy of this message
Lester Caine wrote:
This type of code is used in a few places, so I'd like a little help converting it to 'good code' under the new rules ;)
They're not "new rules". PHP is just warning you where it didn't before. It was still bad coding practice before.
Get the key from an array ( fails because key(&array) ) ---- if( $pId == key( $this->getFunc() ) ) { In getFunc() ---- return ( $this->getAssoc("select Id, Content from database..."); Current fix is just to create the array and use that $keyarray = $this->getFunc(); if( $pGroupId == key( $keyarray ) ) { This works fine, but is there a 'proper' way to do it now that what looked tidy originally fails with an error?
That is the 'proper' way, since you are using key() exactly as it is intended to be used, although you could avoid the reference like this: $keys = array_keys( $this->getFunc() ); if( $pGroupId = $keys[0] ) { -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/

« previous php.general (#222732) next »