note 35249 added to ref.overload
| From: | admin at rack1 dot php dot net | Date: | Mon, 25 Aug 2003 13:51:28 +0000 |
| Subject: | note 35249 added to ref.overload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55037@lists.php.net to get a copy of this message | ||
there are a couple of things you should be aware of when using overloading.
<?
class cTest
{
function __get($key, &$value)
{
echo "get: $key<br />";
return true;
}
function __set($key, $value)
{
echo "set: $key value: $value<br />";
return true;
}
function __call($method, $params, &$return)
{
echo "call: $method params: " . var_export($params, 1) . "<br />";
return true;
}
}
overload('cTest');
$cake = new cTest;
?>
firstly it should be noted that nested classes don't work.
secondly if you try to set an array it somehow becomes a get
and thirdly, if you call a nested class it picks the last nest as the method name, as opposed to a
nested get which picks the first in the list.
<?
$x = $cake->hello->moto; //outputs "get: hello" moto is nowhere to be seen
$cake->hello['moto'] = 4; //outputs "get: hello"
$cake->moo->cow("hello"); //outputs "call: cow params: array ( 0 =>
'hello', )"
?>
bit strange, these occur on php4.3.2. havn't tried other versions
----
Manual Page -- http://www.php.net/manual/en/ref.overload.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35249
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35249&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35249&report=yes