|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-26 23:58 UTC] vik_ at hotmail dot com
Description:
------------
test script $t->priv2 throws
Notice: Undefined property: test::$priv2 error.
Test script:
---------------
class base {
private $priv = "private";
protected $prot = "protected";
public $pub = "public";
final public function __get($prop){
$cv = get_class_vars(__CLASS__); $ccv = get_class_vars(get_called_class());
var_dump('GET--------------', $prop, get_called_class(), __CLASS__, $this, $cv, $ccv, isset($this->$prop), property_exists($this, $prop));
return $this->$prop;
}
final public function __set($prop, $value){
$cv = get_class_vars(__CLASS__); $ccv = get_class_vars(get_called_class());
var_dump('SET--------------', $prop, get_called_class(), __CLASS__, $this, $cv, $ccv, isset($this->$prop), property_exists($this, $prop));
$this->$prop = $value;
}
}
class test extends base {
private $priv2 = "private";
protected $prot2 = "protected";
public $pub2 = "public";
}
// pub2 and prot2 works.
$t = new test();
echo $t->pub2; echo $t->prot2; echo $t->priv2;
Expected result:
----------------
like base class results:
// it works.
$b = new base();
echo $b->pub; echo $b->prot; echo $b->priv;
Actual result:
--------------
Inconsistent behaviour:
1) $this has 6 properties (pub, prot, priv, pub2, prot2, priv2): good
2) get_class_vars(get_called_class()) has 5, priv2 missing: wrong
3) isset($this->$prop) returns false in this case: wrong
4) property_exists($this, $prop)) returns true: good
maybe similar bug: #47808
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 23:00:01 2025 UTC |
addition to my previous post.. toggling the default value of $var in Foo to null and setting it in the constructor: <?php class Foo { #private $var = 'sheep'; private $var; function __construct() { $this->var = 'sheep'; } ... ?> will effect to the following result: ------------------------------------ called $Foo->var(): 0 called $Foo->var: sheep existing property: 1 called $Bar->var(): 0 called $Bar->var: sheep existing property: called $Baz->var(): 1 <----- called $Baz->var: <----- existing property: 1 called $Faz->var(): 0 called $Faz->var: cat existing property: 1