note 54264 rejected from language.oop5.overloading by betz
| From: | betz@php.net | Date: | Wed, 29 Jun 2005 10:14:21 +0000 |
| Subject: | note 54264 rejected from language.oop5.overloading by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-91113@lists.php.net to get a copy of this message | ||
Note Submitter: yayak_baik at plasa dot com
----
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...