Hello Again:

Pardon the followup to myself...

On Fri, Nov 14, 2003 at 05:51:12PM -0500, Daniel Convissor wrote:

> Though, it seems the behavior should be consistent -- sometimes I'm too
> logical :) -- so returning a variable is okay and the rest of it should be
> blocked, OR rework the system so anything can be returend.

I did some more testing on this front and ran into some VERY weird 
behavior which seems to reinforce the point I made above.  The test script 
is below by sig.

Thanks,

--Dan

-- 
     FREE scripts that make web and database programming easier
           http://www.analysisandsolutions.com/software/
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409


<?php

/*
 * Is this an example of memory corruption due to attempting to
 * return by reference on non-variables?
 *
 * BASE OUTPUT:
 *     Ref 1
 *     RefAdd st 10-21-03 06:01 et
 *
 * BUT, the output changes dramatically depending on which lines
 * are commented and uncommented.  Read the block comments below
 * for more information.
 * 
 * PLATFORM:
 *     Windows 2000
 *     PHP 5.0.0b3-dev (cgi-fcgi) (built: Nov 11 2003 16:10:23)
 *     Apache 1.3.28
 */
class x {

    var $int = 1;

    function x() {
        $this->Data['DATETIME'] = 'st 10-21-03 06:01 et';

        /*
         * Commenting out next three lines changes output to:
         *     Ref 1
         *     Fatal error: Cannot return overloaded elements or
         *         string offsets by reference... line 43.
         */
        if ( preg_match('/st (\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d) et/i',
                $this->Data['DATETIME'], $Atom) ) {
        }
    }

    function &Ref() {
        return $this->int;
    }

    function &RefAdd() {
        return ++$this->int;    // Line 43
    }

    function Not() {
        return $this->int;
    }
}

$y = new x;

/*
 * Uncommenting the next two lines changes the output to:
 *     Fatal error: Only variables or references can be returned
 *         by reference... line 43
 */
// $a =& $y->RefAdd();
// echo "<br />RefAdd $a";

$b =& $y->Ref();
echo "<br />Ref $b";

/*
 * Uncommenting the next two lines changes the output to:
 *     Ref 1
 *     Not 1
 *     RefAdd 2
 */
// $c = $y->Not();
// echo "<br />Not $c";

$d =& $y->RefAdd();
echo "<br />RefAdd $d";

?>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to