Mantis - Quercus
Viewing Issue Advanced Details
4542 crash always 05-11-11 13:41 06-21-12 01:17
ronnie_p  
nam  
normal  
closed 4.0.14  
unable to reproduce  
none    
none  
0004542: Can't call method of nested classes
When I try to call a method in a class, which is a part of another class, I get a fatal error:

<?php

class A {
    
    public $foo = NULL;
    
    function __construct()
    {
        $this->foo = '

bar

';
    }
    
    function getFoo()
    {
        return $this->foo;
    }
}

class B {

    public $a = NULL;
    
    function __construct()
    {
        $this->a = new A();
    }
}

// This works
$a = new A();
echo $a->getFoo();

// this doesn't work:
// Fatal Error: Method call 'getFoo' is not allowed for a null value
$b = new B();
try{
    echo $b->a->getFoo();
}
catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "
";
}

// This doesn't works
// Fatal Error: Method call 'getFoo' is not allowed for a null value
$c = $b->a;
try
{
    echo $c->getFoo();
}
catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "
";
}

// This works
$c = &$b->a;
echo $c->getFoo();


echo "

done

";
exit;
?>


Notes
(0005917)
nam   
06-21-12 01:17   
Unable to reproduce for 4.0.29 (upcoming).