Browse Source

Fixed bug #40757 (get_object_vars get nothing in child class)

Fixed bug #41929 (Foreach on object does not iterate over all visible properties)
experimental/5.2-WITH_DRCP
Dmitry Stogov 19 years ago
parent
commit
7ec48cb37f
  1. 3
      NEWS
  2. 4
      Zend/tests/bug27798.phpt
  3. 28
      Zend/tests/bug40757.phpt
  4. 24
      Zend/tests/bug41929.phpt
  5. 16
      Zend/zend_builtin_functions.c
  6. 2
      Zend/zend_object_handlers.c
  7. 20
      ext/pdo/tests/pdo_018.phpt
  8. 1
      tests/classes/visibility_005.phpt

3
NEWS

@ -76,6 +76,8 @@ PHP NEWS
from class hierarchy). (robin_fernandes at uk dot ibm dot com) from class hierarchy). (robin_fernandes at uk dot ibm dot com)
- Fixed bug #41947 (SimpleXML incorrectly registers empty strings as - Fixed bug #41947 (SimpleXML incorrectly registers empty strings as
namespaces). (Rob) namespaces). (Rob)
- Fixed bug #41929 (Foreach on object does not iterate over all visible
properties). (Dmitry)
- Fixed bug #41919 (crash in string to array conversion). - Fixed bug #41919 (crash in string to array conversion).
(judas dot iscariote at gmail dot com, Ilia) (judas dot iscariote at gmail dot com, Ilia)
- Fixed bug #41908 (CFLAGS="-Os" ./configure --enable-debug fails). - Fixed bug #41908 (CFLAGS="-Os" ./configure --enable-debug fails).
@ -160,6 +162,7 @@ PHP NEWS
on Windows). (Scott, Andrey) on Windows). (Scott, Andrey)
- Fixed bug #41127 (Memory leak in ldap_{first|next}_attribute functions). - Fixed bug #41127 (Memory leak in ldap_{first|next}_attribute functions).
(Jani) (Jani)
- Fixed bug #40757 (get_object_vars get nothing in child class). (Dmitry)
- Fixed bug #40419 (Trailing slash in CGI request does not work). (Dmitry) - Fixed bug #40419 (Trailing slash in CGI request does not work). (Dmitry)
- Fixed bug #39330 (apache2handler does not call shutdown actions before - Fixed bug #39330 (apache2handler does not call shutdown actions before
apache child die). (isk at ecommerce dot com, Gopal, Tony) apache child die). (isk at ecommerce dot com, Gopal, Tony)

4
Zend/tests/bug27798.phpt

@ -49,12 +49,12 @@ array(1) {
} }
Base::__construct Base::__construct
array(3) { array(3) {
["Baz"]=>
int(4)
["Foo"]=> ["Foo"]=>
int(1) int(1)
["Bar"]=> ["Bar"]=>
int(2) int(2)
["Baz"]=>
int(3)
} }
Child::__construct Child::__construct
array(3) { array(3) {

28
Zend/tests/bug40757.phpt

@ -0,0 +1,28 @@
--TEST--
Bug #40757 (get_object_vars() get nothing in child class)
--FILE--
<?php
class Base {
private $p1='sadf';
function getFields($obj){
return get_object_vars($obj);
}
}
class Child extends Base { }
$base=new Base();
print_r($base->getFields(new Base()));
$child=new Child();
print_r($child->getFields(new Base()));
?>
--EXPECT--
Array
(
[p1] => sadf
)
Array
(
[p1] => sadf
)

24
Zend/tests/bug41929.phpt

@ -0,0 +1,24 @@
--TEST--
Bug #41929 Foreach on object does not iterate over all visible properties
--FILE--
<?php
class C {
private $priv = "ok";
function doLoop() {
echo $this->priv,"\n";
foreach ($this as $k=>$v) {
echo "$k: $v\n";
}
}
}
class D extends C {
}
$myD = new D;
$myD->doLoop();
?>
--EXPECT--
ok
priv: ok

16
Zend/zend_builtin_functions.c

@ -789,7 +789,7 @@ ZEND_FUNCTION(get_object_vars)
char *key, *prop_name, *class_name; char *key, *prop_name, *class_name;
uint key_len; uint key_len;
ulong num_index; ulong num_index;
int instanceof;
zend_object *zobj;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &obj) == FAILURE) { if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &obj) == FAILURE) {
ZEND_WRONG_PARAM_COUNT(); ZEND_WRONG_PARAM_COUNT();
@ -808,7 +808,7 @@ ZEND_FUNCTION(get_object_vars)
RETURN_FALSE; RETURN_FALSE;
} }
instanceof = EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), Z_OBJCE_PP(obj) TSRMLS_CC);
zobj = zend_objects_get_address(*obj TSRMLS_CC);
array_init(return_value); array_init(return_value);
@ -816,17 +816,11 @@ ZEND_FUNCTION(get_object_vars)
while (zend_hash_get_current_data_ex(properties, (void **) &value, &pos) == SUCCESS) { while (zend_hash_get_current_data_ex(properties, (void **) &value, &pos) == SUCCESS) {
if (zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos) == HASH_KEY_IS_STRING) { if (zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos) == HASH_KEY_IS_STRING) {
if (key[0]) {
if (zend_check_property_access(zobj, key, key_len-1 TSRMLS_CC) == SUCCESS) {
zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name);
/* Not separating references */ /* Not separating references */
(*value)->refcount++; (*value)->refcount++;
add_assoc_zval_ex(return_value, key, key_len, *value);
} else if (instanceof) {
zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name);
if (!memcmp(class_name, "*", 2) || (Z_OBJCE_P(EG(This)) == Z_OBJCE_PP(obj) && !strcmp(Z_OBJCE_P(EG(This))->name, class_name))) {
/* Not separating references */
(*value)->refcount++;
add_assoc_zval_ex(return_value, prop_name, strlen(prop_name)+1, *value);
}
add_assoc_zval_ex(return_value, prop_name, strlen(prop_name)+1, *value);
} }
} }
zend_hash_move_forward_ex(properties, &pos); zend_hash_move_forward_ex(properties, &pos);

2
Zend/zend_object_handlers.c

@ -152,7 +152,7 @@ static int zend_verify_property_access(zend_property_info *property_info, zend_c
case ZEND_ACC_PROTECTED: case ZEND_ACC_PROTECTED:
return zend_check_protected(property_info->ce, EG(scope)); return zend_check_protected(property_info->ce, EG(scope));
case ZEND_ACC_PRIVATE: case ZEND_ACC_PRIVATE:
if (ce==EG(scope) && EG(scope)) {
if ((ce==EG(scope) || property_info->ce == EG(scope)) && EG(scope)) {
return 1; return 1;
} else { } else {
return 0; return 0;

20
ext/pdo/tests/pdo_018.phpt

@ -179,9 +179,9 @@ array(4) {
===INSERT=== ===INSERT===
TestBase::serialize() = 'a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}' TestBase::serialize() = 'a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
TestDerived::serialize() TestDerived::serialize()
TestBase::serialize() = 'a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";}'
TestBase::serialize() = 'a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
TestDerived::serialize() TestDerived::serialize()
TestBase::serialize() = 'a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";}'
TestBase::serialize() = 'a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
===DATA=== ===DATA===
array(4) { array(4) {
[0]=> [0]=>
@ -189,9 +189,9 @@ array(4) {
[1]=> [1]=>
string(91) "a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}" string(91) "a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
[2]=> [2]=>
string(144) "a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";}"
string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
[3]=> [3]=>
string(144) "a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";}"
string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
} }
===FAILURE=== ===FAILURE===
Exception:SQLSTATE[HY000]: General error: cannot unserialize class Exception:SQLSTATE[HY000]: General error: cannot unserialize class
@ -211,22 +211,22 @@ array(3) {
["name"]=> ["name"]=>
string(11) "TestDerived" string(11) "TestDerived"
["val"]=> ["val"]=>
string(144) "a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";}"
string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
} }
[2]=> [2]=>
array(2) { array(2) {
["name"]=> ["name"]=>
NULL NULL
["val"]=> ["val"]=>
string(144) "a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";}"
string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
} }
} }
===FETCHCLASS=== ===FETCHCLASS===
TestBase::unserialize(a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}) TestBase::unserialize(a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
TestDerived::unserialize() TestDerived::unserialize()
TestBase::unserialize(a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";})
TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
TestDerived::unserialize() TestDerived::unserialize()
TestBase::unserialize(a:4:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";})
TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
array(3) { array(3) {
[0]=> [0]=>
object(TestBase)#%d (3) { object(TestBase)#%d (3) {
@ -250,7 +250,7 @@ array(3) {
["DerivedPri:private"]=> ["DerivedPri:private"]=>
string(7) "Private" string(7) "Private"
["BasePri:private"]=> ["BasePri:private"]=>
string(7) "Private"
string(8) "#Private"
} }
[2]=> [2]=>
object(TestLeaf)#%d (6) { object(TestLeaf)#%d (6) {
@ -265,6 +265,6 @@ array(3) {
["DerivedPri:private"]=> ["DerivedPri:private"]=>
string(7) "Private" string(7) "Private"
["BasePri:private"]=> ["BasePri:private"]=>
string(7) "Private"
string(8) "#Private"
} }
} }

1
tests/classes/visibility_005.phpt

@ -52,6 +52,7 @@ d=>4
===derived::function=== ===derived::function===
a=>1 a=>1
b=>2 b=>2
c=>3
d=>4 d=>4
===derived,foreach=== ===derived,foreach===
a=>1 a=>1

Loading…
Cancel
Save