note 54264 added to language.oop5.overloading
| From: | yayak_baik at plasa dot com | Date: | Wed, 29 Jun 2005 02:52:46 +0000 |
| Subject: | note 54264 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91106@lists.php.net to get a copy of this message | ||
When We used virtual variables which should be catch by __get magic method, We encountered errors.
<?php
class TheObj {
public $RealVar1, $RealVar2, $RealVar3, $RealVar4;
public $Var = array();
function __set($var, $val) {
$this->Var[$var] = $val;
}
function __get($var) {
if(isset($this->Var[$var])) return $this->Var[$var];
else return -1;
}
}
$SomeObj = new TheObj;
// this will fine
$SomeObj->RealVar1 = 'somevalue';
$SomeObj->{'RealVar2'} = 'othervalue';
$SomeObj->{'RealVar'.(3)} = 'othervaluetoo';
$SomeObj->{'RealVar'.'4'} = 'anothervalue';
// this will fine too
$SomeObj->Virtual1 = 'somevalue';
$SomeObj->{'Virtual2'} = 'othervalue';
// it's can't be used since this will encounter error
$SomeObj->{'Virtual'.(3)} = 'othervaluetoo';
$SomeObj->{'Virtual'.'4'} = 'anothervalue';
// but you should use it instead
$SomeObj->Var['Virtual'.(3)] = 'othervaluetoo';
$SomeObj->Var['Virtual'.'4'] = 'anothervalue';
var_dump($SomeObj);
?>
Ok, maybe it could help you for saving debugging time.
Btw, it looks like a bug to us...
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54264
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54264&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54264&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54264&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54264&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54264&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54264&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54264&report=yes
Search -- http://master.php.net/manage/user-notes.php