FAQ
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
----------------------------------------------------------------------------

Search Discussions

  • Zeev Suraski at Mar 6, 2005 at 4:51 am

    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
  • Sarose at Mar 6, 2005 at 5:39 am
    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

    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

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Derick Rethans at Mar 6, 2005 at 3:06 pm

    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
  • Yermo Lamers at Mar 6, 2005 at 7:08 pm

    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 at Mar 6, 2005 at 7:20 pm

    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 at Mar 6, 2005 at 7:24 pm

    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
    ----------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedMar 6, '05 at 4:32a
activeMar 6, '05 at 7:24p
posts7
users4
websitephp.net

People

Translate

site design / logo © 2022 Grokbase