com php-src: Don't overload get_properties for ArrayObjec t: ext/reflection/tests/bug61388.phpt ext/spl /spl_array.c
ext/spl/tests/ArrayObject_get_object_v ars.phpt ext/spl/tests/array_017.phpt ext/spl/t ests/bug61347.phpt tests/classes/arrayobject_ 001.phpt
| From: | Nikita Popov | Date: | Wed, 10 Oct 2018 08:39:10 +0000 |
| Subject: | com php-src: Don't overload get_properties for ArrayObjec t: ext/reflection/tests/bug61388.phpt ext/spl /spl_array.c ext/spl/tests/ArrayObject_get_object_v ars.phpt ext/spl/tests/array_017.phpt ext/spl/t ests/bug61347.phpt tests/classes/arrayobject_ 001.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-103422@lists.php.net to get a copy of this message | ||
Commit: a5fa51afbbd87bedeb1c5fd7c9a6cf3c971ab14c
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 5 Oct 2018 15:55:21 +0200
Parents: 1270e5008a1828863a7f96873dff002680eac5c5
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a5fa51afbbd87bedeb1c5fd7c9a6cf3c971ab14c
Log:
Don't overload get_properties for ArrayObject
Instead overload get_properties_for for a few specific cases such
as array casts. This resolves the issue where ArrayObject
get_properties may violate engine invariants in some cases.
Changed paths:
M ext/reflection/tests/bug61388.phpt
M ext/spl/spl_array.c
A ext/spl/tests/ArrayObject_get_object_vars.phpt
M ext/spl/tests/array_017.phpt
M ext/spl/tests/bug61347.phpt
D tests/classes/arrayobject_001.phpt
Diff:
diff --git a/ext/reflection/tests/bug61388.phpt b/ext/reflection/tests/bug61388.phpt
index 3d6dc83..b9fe6bf 100644
--- a/ext/reflection/tests/bug61388.phpt
+++ b/ext/reflection/tests/bug61388.phpt
@@ -14,12 +14,6 @@ print_r($reflObj->getProperties(ReflectionProperty::IS_PUBLIC));
--EXPECT--
Array
(
- [0] => ReflectionProperty Object
- (
- [name] => test
- [class] => ArrayObject
- )
-
)
Array
(
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 63345e6..e2b3ee4 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -807,18 +807,40 @@ SPL_METHOD(Array, getArrayCopy)
RETURN_ARR(zend_array_dup(spl_array_get_hash_table(intern)));
} /* }}} */
-static HashTable *spl_array_get_properties(zval *object) /* {{{ */
+static HashTable *spl_array_get_properties_for(zval *object, zend_prop_purpose purpose) /* {{{ */
{
spl_array_object *intern = Z_SPLARRAY_P(object);
+ HashTable *ht;
+ zend_bool dup;
if (intern->ar_flags & SPL_ARRAY_STD_PROP_LIST) {
- if (!intern->std.properties) {
- rebuild_object_properties(&intern->std);
- }
- return intern->std.properties;
+ return zend_std_get_properties_for(object, purpose);
+ }
+
+ /* We are supposed to be the only owner of the internal hashtable.
+ * The "dup" flag decides whether this is a "long-term" use where
+ * we need to duplicate, or a "temporary" one, where we can expect
+ * that no operations on the ArrayObject will be performed in the
+ * meantime. */
+ switch (purpose) {
+ case ZEND_PROP_PURPOSE_ARRAY_CAST:
+ dup = 1;
+ break;
+ case ZEND_PROP_PURPOSE_VAR_EXPORT:
+ case ZEND_PROP_PURPOSE_JSON:
+ dup = 0;
+ break;
+ default:
+ return zend_std_get_properties_for(object, purpose);
}
- return spl_array_get_hash_table(intern);
+ ht = spl_array_get_hash_table(intern);
+ if (dup) {
+ ht = zend_array_dup(ht);
+ } else {
+ GC_ADDREF(ht);
+ }
+ return ht;
} /* }}} */
static HashTable* spl_array_get_debug_info(zval *obj, int *is_temp) /* {{{ */
@@ -2013,7 +2035,7 @@ PHP_MINIT_FUNCTION(spl_array)
spl_handler_ArrayObject.has_dimension = spl_array_has_dimension;
spl_handler_ArrayObject.count_elements = spl_array_object_count_elements;
- spl_handler_ArrayObject.get_properties = spl_array_get_properties;
+ spl_handler_ArrayObject.get_properties_for = spl_array_get_properties_for;
spl_handler_ArrayObject.get_debug_info = spl_array_get_debug_info;
spl_handler_ArrayObject.get_gc = spl_array_get_gc;
spl_handler_ArrayObject.read_property = spl_array_read_property;
diff --git a/ext/spl/tests/ArrayObject_get_object_vars.phpt
b/ext/spl/tests/ArrayObject_get_object_vars.phpt
new file mode 100644
index 0000000..a80add6
--- /dev/null
+++ b/ext/spl/tests/ArrayObject_get_object_vars.phpt
@@ -0,0 +1,30 @@
+--TEST--
+get_object_vars() on ArrayObject works on the properties of the ArrayObject itself
+--FILE--
+<?php
+
+class Test {
+ public $test;
+ public $test2;
+}
+
+class AO extends ArrayObject {
+ private $test;
+
+ public function getObjectVars() {
+ return get_object_vars($this);
+ }
+}
+
+$ao = new AO(new Test);
+var_dump(get_object_vars($ao));
+var_dump($ao->getObjectVars());
+
+?>
+--EXPECT--
+array(0) {
+}
+array(1) {
+ ["test"]=>
+ NULL
+}
diff --git a/ext/spl/tests/array_017.phpt b/ext/spl/tests/array_017.phpt
index ed12863..0fde103 100644
--- a/ext/spl/tests/array_017.phpt
+++ b/ext/spl/tests/array_017.phpt
@@ -139,13 +139,17 @@ array(3) {
["Flags"]=>
int(0)
["OVars"]=>
- array(3) {
- [0]=>
- int(1)
- ["a"]=>
- int(25)
+ array(5) {
["pub1"]=>
- int(42)
+ int(1)
+ ["pro1"]=>
+ int(2)
+ ["pri1"]=>
+ int(3)
+ ["imp1"]=>
+ int(4)
+ ["dyn1"]=>
+ int(5)
}
["$this"]=>
object(ArrayObjectEx)#%d (6) {
@@ -178,13 +182,17 @@ array(3) {
["Flags"]=>
int(0)
["OVars"]=>
- array(3) {
- [0]=>
+ array(5) {
+ ["pub2"]=>
int(1)
- ["a"]=>
- int(25)
- ["pub1"]=>
- int(42)
+ ["pro2"]=>
+ int(2)
+ ["pri2"]=>
+ int(3)
+ ["imp2"]=>
+ int(4)
+ ["dyn2"]=>
+ int(5)
}
["$this"]=>
object(ArrayIteratorEx)#%d (6) {
@@ -242,13 +250,17 @@ array(3) {
["Flags"]=>
int(0)
["OVars"]=>
- array(3) {
- [0]=>
+ array(5) {
+ ["pub2"]=>
int(1)
- ["a"]=>
- int(25)
- ["pub1"]=>
- int(42)
+ ["pro2"]=>
+ int(2)
+ ["pri2"]=>
+ int(3)
+ ["imp2"]=>
+ int(4)
+ ["dyn2"]=>
+ int(5)
}
["$this"]=>
object(ArrayIteratorEx)#%d (6) {
@@ -541,14 +553,16 @@ array(3) {
["Flags"]=>
int(0)
["OVars"]=>
- array(4) {
- ["pub1"]=>
+ array(5) {
+ ["pub2"]=>
int(1)
- ["pro1"]=>
+ ["pro2"]=>
int(2)
- ["imp1"]=>
+ ["pri2"]=>
+ int(3)
+ ["imp2"]=>
int(4)
- ["dyn1"]=>
+ ["dyn2"]=>
int(5)
}
["$this"]=>
@@ -598,14 +612,16 @@ array(3) {
["Flags"]=>
int(0)
["OVars"]=>
- array(4) {
- ["pub1"]=>
+ array(5) {
+ ["pub2"]=>
int(1)
- ["pro1"]=>
+ ["pro2"]=>
int(2)
- ["imp1"]=>
+ ["pri2"]=>
+ int(3)
+ ["imp2"]=>
int(4)
- ["dyn1"]=>
+ ["dyn2"]=>
int(5)
}
["$this"]=>
diff --git a/ext/spl/tests/bug61347.phpt b/ext/spl/tests/bug61347.phpt
index cb09185..720cf5b 100644
--- a/ext/spl/tests/bug61347.phpt
+++ b/ext/spl/tests/bug61347.phpt
@@ -12,7 +12,7 @@ var_dump(isset($b['no_exists'])); //false
var_dump(empty($b['b'])); //true
var_dump(empty($b[37])); //true
-var_dump(array_key_exists('b', $b)); //true
+var_dump(array_key_exists('b', $b)); //false
var_dump($b['b']);
$a = array('b' => '', 37 => false);
@@ -31,7 +31,7 @@ bool(false)
bool(false)
bool(true)
bool(true)
-bool(true)
+bool(false)
NULL
bool(true)
bool(true)
diff --git a/tests/classes/arrayobject_001.phpt b/tests/classes/arrayobject_001.phpt
deleted file mode 100644
index b75f8c7..0000000
--- a/tests/classes/arrayobject_001.phpt
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-Ensure that ArrayObject acts like an array
---FILE--
-<?php
-
-$a = new ArrayObject;
-$a['foo'] = 'bar';
-echo reset($a);
-echo count($a);
-echo current($a);
-?>
---EXPECT--
-bar1bar