PHP 5.0.3 E_STRICT question - returning NULL from reference returning function

php.internals

Yermo Lamers

21 years ago
What is the proper way to return a NULL condition from a method that returns a reference? function &testfunc() { return NULL; } generates: "Strict Standards: Only variable references should be returned by reference in ..." Is the correct approach to do something like: function &testfunc() { $nullVar = NULL; return $nullVar; } ?? ---------------------------------------------------------------------------- DTLink Software http://www.dtlink.com Desktop Software and Web Applications ----------------------------------------------------------------------------

Zeev Suraski

21 years ago
At 06:47 06/03/2005, Yermo Lamers wrote:
>What is the proper way to return a NULL condition from a method that >returns a reference? > >function &testfunc() >{ >return NULL; >} > >generates: > >"Strict Standards: Only variable references should be returned by >reference in ..." > >Is the correct approach to do something like: > >function &testfunc() >{ >$nullVar = NULL; >return $nullVar; >}
That'd work, yep. Zeev

npguy

21 years ago
Just curious what is the techincal aspect of the such case. Why need NULL identifier for the return not NULL iteself. ----- Original Message ----- From: "Zeev Suraski" <zeev@zend.com> To: <yml@dtlink.com> Cc: <internals@lists.php.net> Sent: Sunday, March 06, 2005 10:36 AM Subject: Re: [PHP-DEV] PHP 5.0.3 E_STRICT question - returning NULLfrom reference returning function

Derick Rethans

21 years ago
On Sun, 6 Mar 2005, Zeev Suraski wrote:
> At 06:47 06/03/2005, Yermo Lamers wrote: > > >What is the proper way to return a NULL condition from a method that > >returns a reference? > > > >function &testfunc() > >{ > >return NULL; > >} > > > >generates: > > > >"Strict Standards: Only variable references should be returned by > >reference in ..." > > > >Is the correct approach to do something like: > > > >function &testfunc() > >{ > >$nullVar = NULL; > >return $nullVar; > >} > > That'd work, yep.
Wrong ;-) It causes problems with reference counting - and will segfault PHP after some time. Derick
-- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org

Yermo Lamers

21 years ago
>> >Is the correct approach to do something like: >> > >> >function &testfunc() >> >{ >> >$nullVar = NULL; >> >return $nullVar; >> >} >> >> That'd work, yep. > > Wrong ;-) It causes problems with reference counting - and will segfault > PHP after some time. > > Derick
Then what is the correct approach to handling this? -- Yermo ---------------------------------------------------------------------------- DTLink Software http://www.dtlink.com Desktop Software and Web Applications ----------------------------------------------------------------------------

Zeev Suraski

21 years ago
At 17:06 06/03/2005, Derick Rethans wrote:
>On Sun, 6 Mar 2005, Zeev Suraski wrote: > > > At 06:47 06/03/2005, Yermo Lamers wrote: > > > > >What is the proper way to return a NULL condition from a method that > > >returns a reference? > > > > > >function &testfunc() > > >{ > > >return NULL; > > >} > > > > > >generates: > > > > > >"Strict Standards: Only variable references should be returned by > > >reference in ..." > > > > > >Is the correct approach to do something like: > > > > > >function &testfunc() > > >{ > > >$nullVar = NULL; > > >return $nullVar; > > >} > > > > That'd work, yep. > >Wrong ;-) It causes problems with reference counting - and will segfault >PHP after some time.
Hmm, that in itself shouldn't cause any problems unless it's coupled with something else that's causing problems... Not that it helps you any if you end up bumping into problems :) Zeev

Yermo Lamers

21 years ago
>> > >function &testfunc() >> > >{ >> > >$nullVar = NULL; >> > >return $nullVar; >> > >} >> > >> > That'd work, yep. >> >>Wrong ;-) It causes problems with reference counting - and will segfault >>PHP after some time. > > Hmm, that in itself shouldn't cause any problems unless it's coupled with > something else that's causing problems... Not that it helps you any if > you end up bumping into problems :)
True; but it's good to know what the "correct" thing to do is; even if there is an underlying bug. -- Yermo ---------------------------------------------------------------------------- DTLink Software http://www.dtlink.com Desktop Software and Web Applications ----------------------------------------------------------------------------