note 62303 added to ref.overload
| From: | daniel at softel dot jp | Date: | Fri, 24 Feb 2006 17:13:55 +0000 |
| Subject: | note 62303 added to ref.overload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104373@lists.php.net to get a copy of this message | ||
Note that with this class:
<?php
class SillyClass
{
private $config = array();
public function __construct()
{
$this->config['fruit'] = 'banana';
$this->config['animal'] = 'monkey';
$this->config['shoppingList'] =
array('drink' => 'milk', 'food' =>
'cheeseburger');
}
//Allow mySillyClass->someProperty style getting of
//anything that might happen to be in the $config array
//(returns NULL if not in the $config array).
public function __get($property)
{
if(isset($this->config->$property))
{
return $this->config->$property;
}
}
}
?>
The following code can not be used:
<?php
$mySillyClass = new SillyClass();
$drinkToBuy = $mySillyClass->shoppingList->drink;
?>
It seems that although there is no error, $mySillyClass->someProperty->someProperty
does *not* work (__get() is only called once).
It's not really a bug, and I'm sure PHP is behaving properly but it had me stumped for a
while!
----
Server IP: 61.195.146.164
Probable Submitter: 138.243.201.10
----
Manual Page -- http://www.php.net/manual/en/ref.overload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+62303
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62303&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+62303&report=yes
Search -- http://master.php.net/manage/user-notes.php