Re: when $a = &new class is necessary

From: Date: Mon, 24 Sep 2007 16:24:07 +0000
Subject: Re: when $a = &new class is necessary
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-48161@lists.php.net to get a copy of this message
Christian Schmidt wrote: > Gregory Beaver wrote: >> As the push to make the PHP 4 code closer to PHP 5 E_STRICT takes place, >> I thought it might be helpful to have a guide for when $a = &new class >> is necessary, and when & is necessary for function parameters that are >> objects. > > I agree with the point raised by Justin Patrin that dealing with > references are somewhat risky if you are not careful. > > To reduce this risk and help package owners who want to make their PHP4 > packages "PHP5-friendly", it may be worth introducing a utility function > that handles the delicate art of handling PHP4 references. For example > replace "$foo =& new Bar($bla)" with "$foo =& > PEAR::makeNew('Bar', $bla)". > > This isn't pretty, but it is less likely to have unknown side effects > that just replacing "$foo =& new Bar" with "$foo = new Bar". This will replace 1 E_STRICT with another, as we won't be able to use the "static" keyword. The only solution is to remove unnecessary &, and to leave necessary &, or to refactor so that & is not necessary. Refactoring is often not possible without breaking BC, unfortunately. Greg

« previous php.pear.dev (#48161) next »