cvs: ZendEngine2(PHP_5_3) / zend_builtin_functions.c /tests bug45862.phpt get_class_vars_001.phpt get_class_vars_002.phpt get_class_vars_003.phpt
get_class_vars_004.phpt get_class_vars_005.phpt get_class_vars_006.phpt get_class_vars_007.phpt
| From: | Felipe Pena | Date: | Fri, 22 Aug 2008 00:59:40 +0000 |
| Subject: | cvs: ZendEngine2(PHP_5_3) / zend_builtin_functions.c /tests bug45862.phpt get_class_vars_001.phpt get_class_vars_002.phpt get_class_vars_003.phpt get_class_vars_004.phpt get_class_vars_005.phpt get_class_vars_006.phpt get_class_vars_007.phpt |
||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-7089@lists.php.net to get a copy of this message | ||
felipe Fri Aug 22 00:59:40 2008 UTC
Added files: (Branch: PHP_5_3)
/ZendEngine2/tests bug45862.phpt get_class_vars_001.phpt
get_class_vars_002.phpt get_class_vars_003.phpt
get_class_vars_004.phpt get_class_vars_005.phpt
get_class_vars_006.phpt get_class_vars_007.phpt
Modified files:
/ZendEngine2 zend_builtin_functions.c
Log:
MFH:
- Fixed bug #45862 (get_class_vars is inconsistent with 'protected' and
'private' variables)
- Added some tests
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_builtin_functions.c?r1=1.277.2.12.2.25.2.28&r2=1.277.2.12.2.25.2.29&diff_format=u Index: ZendEngine2/zend_builtin_functions.c diff -u ZendEngine2/zend_builtin_functions.c:1.277.2.12.2.25.2.28 ZendEngine2/zend_builtin_functions.c:1.277.2.12.2.25.2.29 --- ZendEngine2/zend_builtin_functions.c:1.277.2.12.2.25.2.28 Mon Aug 18 17:44:02 2008 +++ ZendEngine2/zend_builtin_functions.c Fri Aug 22 00:59:39 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_builtin_functions.c,v 1.277.2.12.2.25.2.28 2008/08/18 17:44:02 felipe Exp $ */ +/* $Id: zend_builtin_functions.c,v 1.277.2.12.2.25.2.29 2008/08/22 00:59:39 felipe Exp $ */ #include "zend.h" #include "zend_API.h" @@ -977,8 +977,6 @@ /* {{{ add_class_vars */ static void add_class_vars(zend_class_entry *ce, HashTable *properties, zval *return_value TSRMLS_DC) { - int instanceof = EG(scope) && instanceof_function(EG(scope), ce TSRMLS_CC); - if (zend_hash_num_elements(properties) > 0) { HashPosition pos; zval **prop; @@ -987,20 +985,28 @@ while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) { char *key, *class_name, *prop_name; uint key_len; - ulong num_index; + ulong num_index, h; + int prop_name_len = 0; zval *prop_copy; + zend_property_info *property_info; zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos); zend_hash_move_forward_ex(properties, &pos); + zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name); - if (class_name) { - if (class_name[0] != '*' && strcmp(class_name, ce->name)) { - /* filter privates from base classes */ - continue; - } else if (!instanceof) { - /* filter protected if not inside class */ - continue; - } + prop_name_len = strlen(prop_name); + + h = zend_get_hash_value(prop_name, prop_name_len+1); + if (zend_hash_quick_find(&ce->properties_info, prop_name, prop_name_len+1, h, (void **) &property_info) == FAILURE) { + continue; + } + + if (property_info->flags & ZEND_ACC_SHADOW) { + continue; + } else if ((property_info->flags & ZEND_ACC_PRIVATE) && EG(scope) != ce) { + continue; + } else if ((property_info->flags & ZEND_ACC_PROTECTED) && zend_check_protected(ce, EG(scope)) == 0) { + continue; } /* copy: enforce read only access */ http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug45862.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/bug45862.phpt +++ ZendEngine2/tests/bug45862.phpt --TEST-- Bug #45862 (get_class_vars is inconsistent with 'protected' and 'private' variables) --FILE-- <?php class Ancestor { function test() { var_dump(get_class_vars("Tester")); var_dump(Tester::$prot); } } class Tester extends Ancestor { static protected $prot = "protected var"; static private $priv = "private var"; } class Child extends Tester { function test() { var_dump(get_class_vars("Tester")); } } echo "\n From parent scope\n"; $parent = new Ancestor(); $parent->test(); echo "\n From child scope\n"; $child = new Child(); $child->test(); ?> --EXPECT-- From parent scope array(1) { [u"prot"]=> unicode(13) "protected var" } unicode(13) "protected var" From child scope array(1) { [u"prot"]=> unicode(13) "protected var" } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_001.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_001.phpt +++ ZendEngine2/tests/get_class_vars_001.phpt --TEST-- get_class_vars(): Simple test --FILE-- <?php class A { public $a = 1; private $b = 2; private $c = 3; } class B extends A { static public $aa = 4; static private $bb = 5; static protected $cc = 6; } var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); ?> --EXPECT-- array(1) { [u"a"]=> int(1) } array(2) { [u"a"]=> int(1) [u"aa"]=> int(4) } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_002.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_002.phpt +++ ZendEngine2/tests/get_class_vars_002.phpt --TEST-- get_class_vars(): Testing the scope --FILE-- <?php class A { public $a = 1; private $b = 2; private $c = 3; } class B extends A { static public $aa = 4; static private $bb = 5; static protected $cc = 6; } class C extends B { public function __construct() { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); var_dump($this->a, $this->b, $this->c); } } new C; ?> --EXPECTF-- array(1) { [u"a"]=> int(1) } array(3) { [u"a"]=> int(1) [u"aa"]=> int(4) [u"cc"]=> int(6) } Notice: Undefined property: C::$b in %s on line %d Notice: Undefined property: C::$c in %s on line %d int(1) NULL NULL http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_003.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_003.phpt +++ ZendEngine2/tests/get_class_vars_003.phpt --TEST-- get_class_vars(): Testing the scope --FILE-- <?php class A { public $a = 1; private $b = 2; private $c = 3; } class B extends A { static public $aa = 4; static private $bb = 5; static protected $cc = 6; protected function __construct() { var_dump(get_class_vars('C')); } } class C extends B { public $aaa = 7; private $bbb = 8; protected $ccc = 9; public function __construct() { parent::__construct(); } } new C; ?> --EXPECT-- array(5) { [u"aaa"]=> int(7) [u"ccc"]=> int(9) [u"a"]=> int(1) [u"aa"]=> int(4) [u"cc"]=> int(6) } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_004.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_004.phpt +++ ZendEngine2/tests/get_class_vars_004.phpt --TEST-- get_class_vars(): Testing the scope --FILE-- <?php class A { public $a = 1; static public $A = 2; private $b = 3; static private $B = 4; protected $c = 5; static protected $C = 6; public function __construct() { var_dump(get_class_vars('A')); } static public function test() { var_dump(get_class_vars('A')); } } var_dump(get_class_vars('A')); new A; var_dump(A::test()); ?> --EXPECT-- array(2) { [u"a"]=> int(1) [u"A"]=> int(2) } array(6) { [u"a"]=> int(1) [u"b"]=> int(3) [u"c"]=> int(5) [u"A"]=> int(2) [u"B"]=> int(4) [u"C"]=> int(6) } array(6) { [u"a"]=> int(1) [u"b"]=> int(3) [u"c"]=> int(5) [u"A"]=> int(2) [u"B"]=> int(4) [u"C"]=> int(6) } NULL http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_005.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_005.phpt +++ ZendEngine2/tests/get_class_vars_005.phpt --TEST-- get_class_vars(): Testing visibility --FILE-- <?php class A { protected $a = 1; private $b = 2; } class B extends A { private $c = 3; public function __construct() { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); } } var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); new B; ?> --EXPECT-- array(0) { } array(0) { } array(1) { [u"a"]=> int(1) } array(2) { [u"c"]=> int(3) [u"a"]=> int(1) } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_006.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_006.phpt +++ ZendEngine2/tests/get_class_vars_006.phpt --TEST-- get_class_vars(): Testing visibility --FILE-- <?php class A { protected $a = 1; } class B extends A { } class C extends B { } var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); var_dump(get_class_vars('C')); print "---\n"; class D extends B { public function __construct() { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); var_dump(get_class_vars('C')); } } new D; ?> --EXPECT-- array(0) { } array(0) { } array(0) { } --- array(1) { [u"a"]=> int(1) } array(1) { [u"a"]=> int(1) } array(0) { } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_007.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_007.phpt +++ ZendEngine2/tests/get_class_vars_007.phpt --TEST-- get_class_vars(): Testing with static properties --FILE-- <?php class A { static public $a, $aa; static private $b, $bb; static protected $c, $cc; static public function test() { var_dump(get_class_vars(__CLASS__)); } } var_dump(get_class_vars('A')); var_dump(A::test()); ?> --EXPECT-- array(2) { [u"a"]=> NULL [u"aa"]=> NULL } array(6) { [u"a"]=> NULL [u"aa"]=> NULL [u"b"]=> NULL [u"bb"]=> NULL [u"c"]=> NULL [u"cc"]=> NULL } NULL
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_builtin_functions.c?r1=1.277.2.12.2.25.2.28&r2=1.277.2.12.2.25.2.29&diff_format=u Index: ZendEngine2/zend_builtin_functions.c diff -u ZendEngine2/zend_builtin_functions.c:1.277.2.12.2.25.2.28 ZendEngine2/zend_builtin_functions.c:1.277.2.12.2.25.2.29 --- ZendEngine2/zend_builtin_functions.c:1.277.2.12.2.25.2.28 Mon Aug 18 17:44:02 2008 +++ ZendEngine2/zend_builtin_functions.c Fri Aug 22 00:59:39 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_builtin_functions.c,v 1.277.2.12.2.25.2.28 2008/08/18 17:44:02 felipe Exp $ */ +/* $Id: zend_builtin_functions.c,v 1.277.2.12.2.25.2.29 2008/08/22 00:59:39 felipe Exp $ */ #include "zend.h" #include "zend_API.h" @@ -977,8 +977,6 @@ /* {{{ add_class_vars */ static void add_class_vars(zend_class_entry *ce, HashTable *properties, zval *return_value TSRMLS_DC) { - int instanceof = EG(scope) && instanceof_function(EG(scope), ce TSRMLS_CC); - if (zend_hash_num_elements(properties) > 0) { HashPosition pos; zval **prop; @@ -987,20 +985,28 @@ while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) { char *key, *class_name, *prop_name; uint key_len; - ulong num_index; + ulong num_index, h; + int prop_name_len = 0; zval *prop_copy; + zend_property_info *property_info; zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos); zend_hash_move_forward_ex(properties, &pos); + zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name); - if (class_name) { - if (class_name[0] != '*' && strcmp(class_name, ce->name)) { - /* filter privates from base classes */ - continue; - } else if (!instanceof) { - /* filter protected if not inside class */ - continue; - } + prop_name_len = strlen(prop_name); + + h = zend_get_hash_value(prop_name, prop_name_len+1); + if (zend_hash_quick_find(&ce->properties_info, prop_name, prop_name_len+1, h, (void **) &property_info) == FAILURE) { + continue; + } + + if (property_info->flags & ZEND_ACC_SHADOW) { + continue; + } else if ((property_info->flags & ZEND_ACC_PRIVATE) && EG(scope) != ce) { + continue; + } else if ((property_info->flags & ZEND_ACC_PROTECTED) && zend_check_protected(ce, EG(scope)) == 0) { + continue; } /* copy: enforce read only access */ http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug45862.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/bug45862.phpt +++ ZendEngine2/tests/bug45862.phpt --TEST-- Bug #45862 (get_class_vars is inconsistent with 'protected' and 'private' variables) --FILE-- <?php class Ancestor { function test() { var_dump(get_class_vars("Tester")); var_dump(Tester::$prot); } } class Tester extends Ancestor { static protected $prot = "protected var"; static private $priv = "private var"; } class Child extends Tester { function test() { var_dump(get_class_vars("Tester")); } } echo "\n From parent scope\n"; $parent = new Ancestor(); $parent->test(); echo "\n From child scope\n"; $child = new Child(); $child->test(); ?> --EXPECT-- From parent scope array(1) { [u"prot"]=> unicode(13) "protected var" } unicode(13) "protected var" From child scope array(1) { [u"prot"]=> unicode(13) "protected var" } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_001.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_001.phpt +++ ZendEngine2/tests/get_class_vars_001.phpt --TEST-- get_class_vars(): Simple test --FILE-- <?php class A { public $a = 1; private $b = 2; private $c = 3; } class B extends A { static public $aa = 4; static private $bb = 5; static protected $cc = 6; } var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); ?> --EXPECT-- array(1) { [u"a"]=> int(1) } array(2) { [u"a"]=> int(1) [u"aa"]=> int(4) } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_002.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_002.phpt +++ ZendEngine2/tests/get_class_vars_002.phpt --TEST-- get_class_vars(): Testing the scope --FILE-- <?php class A { public $a = 1; private $b = 2; private $c = 3; } class B extends A { static public $aa = 4; static private $bb = 5; static protected $cc = 6; } class C extends B { public function __construct() { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); var_dump($this->a, $this->b, $this->c); } } new C; ?> --EXPECTF-- array(1) { [u"a"]=> int(1) } array(3) { [u"a"]=> int(1) [u"aa"]=> int(4) [u"cc"]=> int(6) } Notice: Undefined property: C::$b in %s on line %d Notice: Undefined property: C::$c in %s on line %d int(1) NULL NULL http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_003.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_003.phpt +++ ZendEngine2/tests/get_class_vars_003.phpt --TEST-- get_class_vars(): Testing the scope --FILE-- <?php class A { public $a = 1; private $b = 2; private $c = 3; } class B extends A { static public $aa = 4; static private $bb = 5; static protected $cc = 6; protected function __construct() { var_dump(get_class_vars('C')); } } class C extends B { public $aaa = 7; private $bbb = 8; protected $ccc = 9; public function __construct() { parent::__construct(); } } new C; ?> --EXPECT-- array(5) { [u"aaa"]=> int(7) [u"ccc"]=> int(9) [u"a"]=> int(1) [u"aa"]=> int(4) [u"cc"]=> int(6) } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_004.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_004.phpt +++ ZendEngine2/tests/get_class_vars_004.phpt --TEST-- get_class_vars(): Testing the scope --FILE-- <?php class A { public $a = 1; static public $A = 2; private $b = 3; static private $B = 4; protected $c = 5; static protected $C = 6; public function __construct() { var_dump(get_class_vars('A')); } static public function test() { var_dump(get_class_vars('A')); } } var_dump(get_class_vars('A')); new A; var_dump(A::test()); ?> --EXPECT-- array(2) { [u"a"]=> int(1) [u"A"]=> int(2) } array(6) { [u"a"]=> int(1) [u"b"]=> int(3) [u"c"]=> int(5) [u"A"]=> int(2) [u"B"]=> int(4) [u"C"]=> int(6) } array(6) { [u"a"]=> int(1) [u"b"]=> int(3) [u"c"]=> int(5) [u"A"]=> int(2) [u"B"]=> int(4) [u"C"]=> int(6) } NULL http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_005.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_005.phpt +++ ZendEngine2/tests/get_class_vars_005.phpt --TEST-- get_class_vars(): Testing visibility --FILE-- <?php class A { protected $a = 1; private $b = 2; } class B extends A { private $c = 3; public function __construct() { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); } } var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); new B; ?> --EXPECT-- array(0) { } array(0) { } array(1) { [u"a"]=> int(1) } array(2) { [u"c"]=> int(3) [u"a"]=> int(1) } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_006.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_006.phpt +++ ZendEngine2/tests/get_class_vars_006.phpt --TEST-- get_class_vars(): Testing visibility --FILE-- <?php class A { protected $a = 1; } class B extends A { } class C extends B { } var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); var_dump(get_class_vars('C')); print "---\n"; class D extends B { public function __construct() { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); var_dump(get_class_vars('C')); } } new D; ?> --EXPECT-- array(0) { } array(0) { } array(0) { } --- array(1) { [u"a"]=> int(1) } array(1) { [u"a"]=> int(1) } array(0) { } http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/get_class_vars_007.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/get_class_vars_007.phpt +++ ZendEngine2/tests/get_class_vars_007.phpt --TEST-- get_class_vars(): Testing with static properties --FILE-- <?php class A { static public $a, $aa; static private $b, $bb; static protected $c, $cc; static public function test() { var_dump(get_class_vars(__CLASS__)); } } var_dump(get_class_vars('A')); var_dump(A::test()); ?> --EXPECT-- array(2) { [u"a"]=> NULL [u"aa"]=> NULL } array(6) { [u"a"]=> NULL [u"aa"]=> NULL [u"b"]=> NULL [u"bb"]=> NULL [u"c"]=> NULL [u"cc"]=> NULL } NULL