note 84500 added to language.oop5.overloading
| From: | strafvollzugsbeamter at gmx dot de | Date: | Wed, 16 Jul 2008 19:57:09 +0000 |
| Subject: | note 84500 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141584@lists.php.net to get a copy of this message | ||
The following works on my installation (5.2.6 / Windows):
<?php
class G
{
private $_p = array();
public function __isset($k)
{
return isset($this->_p[$k]);
}
public function __get($k)
{
$v = NULL;
if (array_key_exists($k, $this->_p))
{
$v = $this->_p[$k];
}
else
{
$v = $this->{$k} = $this;
}
return $v;
}
public function __set($k, $v)
{
$this->_p[$k] = $v;
return $this;
}
}
$s = new G();
$s->A->B->C = 'FOO';
$s->X->Y->Z = array ('BAR');
if (isset($s->A->B->C))
{
print($s->A->B->C);
}
else
{
print('A->B->C is NOT set');
}
if (isset($s->X->Y->Z))
{
print_r($s->X->Y->Z);
}
else
{
print('X->Y->Z is NOT set');
}
// prints: FOOArray ( [0] => BAR )
?>
... have fun and ...
----
Server IP: 217.160.72.57
Probable Submitter: 91.36.228.156
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/84500
Del: integrated -- https://master.php.net/note/delete/84500/integrated
Del: useless -- https://master.php.net/note/delete/84500/useless
Del: bad code -- https://master.php.net/note/delete/84500/bad+code
Del: spam -- https://master.php.net/note/delete/84500/spam
Del: non-english -- https://master.php.net/note/delete/84500/non-english
Del: in docs -- https://master.php.net/note/delete/84500/in+docs
Del: other reasons-- https://master.php.net/note/delete/84500
Reject -- https://master.php.net/note/reject/84500
Search -- https://master.php.net/manage/user-notes.php