note 55486 modified in language.oop5.overloading by danbrown
| From: | danbrown@php.net | Date: | Fri, 14 Nov 2008 17:19:53 +0000 |
| Subject: | note 55486 modified in language.oop5.overloading by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146552@lists.php.net to get a copy of this message | ||
By Design (http://bugs.php.net/bug.php?id=33998) you cannot call a getter from a getter or any
function triggered by a getter:
<?php
class test
{
protected $_a = 6;
function __get($key) {
if($key == 'stuff') {
return $this->stuff();
} else if($key == 'a') {
return $this->_a;
}
}
function stuff()
{
return array('random' => 'key', 'using_getter' => 10 *
$this->a);
}
}
$test = new test();
print 'this should be 60:
'.$test->stuff['using_getter'].'<br/>'; // prints "this
should be 60: 0"
// [[ Undefined property: test::$a ]] on /var/www/html/test.php logged.
print 'this should be 6: '.$test->a.'<br/>';
// prints "this should be 6: 6"
?>
--was--
By Design (http://bugs.php.net/bug.php?id=33998) you cannot call a getter from a getter or any
function triggered by a getter:
class test
{
protected $_a = 6;
function __get($key) {
if($key == 'stuff') {
return $this->stuff();
} else if($key == 'a') {
return $this->_a;
}
}
function stuff()
{
return array('random' => 'key', 'using_getter' => 10 *
$this->a);
}
}
$test = new test();
print 'this should be 60:
'.$test->stuff['using_getter'].'<br/>'; // prints "this
should be 60: 0"
// [[ Undefined property: test::$a ]] on /var/www/html/test.php logged.
print 'this should be 6: '.$test->a.'<br/>';
// prints "this should be 6: 6"
http://php.net/manual/en/language.oop5.overloading.php