If you are looking for the epic motorcycle journey blog that I've written, please see the Miles By Motorcycle site I put together. 
  • PHP 5.0.3 and 4.3.10 mystery solved.
    03/06/2005 2:32PM
    See the article over at formvista.com.

    It turns out that if you have a function that returns a reference there are two things you have to keep in mind:

    function &someFunc()
    {
    ...
    return( $var )
    }

    is incorrect PHP as the ()'s after the return indicate that it's returning an expression and expressions cannot evaluate to references. Apparently up through PHP 5.0.2 there was a bug that allowed this construct to work most of the time. However, it did introduce some instability in the parser apparently causing all these weird crash/symbol table corruption bugs I've been reporting.

    Another thing to note is that functions that returns references cannot return NULL, so:

    function &someFunc()
    {
    return NULL;
    }

    is incorrect and under PHP 5 will generate a warning when you have E_STRICT warnings turned on php.ini. (NOTE, E_ALL in php.ini does /NOT/ include E_STRICT).

    The "correct" approach is to:

    function &someFunc()
    {
    $nullVar = NULL;
    return $nullvar;
    }

    It's been reported that there is a bug that will cause a segfault using this construct, but I'm told this is valid PHP.

    Of course, both cases IMHO should just work. Expressions should be able to evaluate to references and a function returning a reference should be able to return NULL. And in either case incorrectly calling return with an expression should not cause PHP to dump core or trash the symbol table.

    Additionally, IMHO the case of returning a reference in an expression should generate an error; not just a warning when you turn on E_STRICT.

    Just my $0.02.