why do the following two examples result in different things, even 
though i would expect the same behaviour?

in words: i pass a reference of a class-property to a variable $walk, 
if i overwrite $walk, the class-property has a new value too (seems 
logical, since we are working with references not pointers)
BUT
if i use a class-method which returns a reference to this 
class-property, to set $walk ... and then i overwrite $walk the 
class-property didnt change


code-example
<?php

class test
{
    var $data;
    function test()
    {
        $this->data[0] = 'level zero';
        $this->data[1] = 'level one';
    }

    function &getData( $id )
    {
        return $this->data[$id];
    }
}

$test = new test;
print('<br>');
print_r($test);

// the following block overwrites $test->data[0] with $test->data[1]
$walk = &$test->data[0];
$walk = $test->data[1];
print('<br>');
print_r($test);


$test = new test;
// but this one does NOT !!!
$walk = $test->getData(0);
$walk = $test->data[1];
print('<br>');
print_r($test);

?>

-- 
Wolfram

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to