Skip to content

ext/spl: Deprecate ArrayObject and ArrayIterator with objects #19420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Zend/tests/gc/gc_046.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ $action->filter();
$action->filter();
?>
DONE
--EXPECT--
--EXPECTF--
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
DONE
3 changes: 2 additions & 1 deletion Zend/tests/type_declarations/typed_properties_113.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ foreach ($obj as $k => &$v) {

var_dump($obj);
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(A)#1 (1) {
["foo"]=>
&string(2) "42"
Expand Down
5 changes: 4 additions & 1 deletion Zend/tests/type_declarations/typed_properties_114.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ foreach ($obj as $k => &$v) {

var_dump($obj);
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
Cannot assign array to reference held by property A::$foo of type string

Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
Cannot assign array to reference held by property A::$foo of type string
object(A)#1 (1) {
["foo"]=>
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/type_declarations/typed_properties_115.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ try {

var_dump($obj);
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
Cannot acquire reference to readonly property A::$foo
object(A)#1 (1) {
["foo"]=>
Expand Down
6 changes: 6 additions & 0 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,12 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
}
}
} else {
php_error_docref(NULL, E_DEPRECATED,
"Using an object as a backing array for %s is deprecated, as it allows violating class constraints and invariants",
instanceof_function(Z_OBJCE_P(object), spl_ce_ArrayIterator) ? "ArrayIterator" : "ArrayObject");
if (UNEXPECTED(EG(exception))) {
return;
}
if (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject) {
ZVAL_COPY_VALUE(&garbage, &intern->array);
if (just_array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ $c = clone $b;
var_dump($c);

?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(ArrayObject)#3 (1) {
["storage":"ArrayObject":private]=>
array(3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ new ArrayObject(Foo::Bar);

?>
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Fatal error: Uncaught InvalidArgumentException: Enums are not compatible with ArrayObject in %s:%d
%a
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var_dump(get_object_vars($ao));
var_dump($ao->getObjectVars());

?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
array(0) {
}
array(1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ $ao['a'] = 42;
var_dump($arr);

?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
array(2) {
["a"]=>
int(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ try {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
Overloaded object of type SplFixedArray is not compatible with ArrayObject
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ try {
var_dump($ao);

?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
Overloaded object of type DateInterval is not compatible with ArrayObject
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
When ArrayObject wraps an object, we should use proptable canonicalization
When ArrayObject wraps an object, we should use prop table canonicalization
--FILE--
<?php

Expand All @@ -15,7 +15,8 @@ unset($ao[0]);
var_dump($o);

?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(stdClass)#1 (1) {
["0"]=>
int(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var_dump($ao5);

?>
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
object(stdClass)#1 (2) {
Expand All @@ -38,6 +39,8 @@ object(ArrayObject)#2 (1) {
int(2)
}
}

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(ArrayObject)#3 (1) {
["storage":"ArrayObject":private]=>
object(ArrayObject)#2 (1) {
Expand All @@ -51,6 +54,8 @@ object(ArrayObject)#3 (1) {
}
}

Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Deprecated: Creation of dynamic property ArrayObject::$a is deprecated in %s on line %d

Deprecated: Creation of dynamic property ArrayObject::$b is deprecated in %s on line %d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var_dump((array) $c);
--EXPECTF--
Deprecated: Creation of dynamic property ArrayObject::$prop is deprecated in %s on line %d

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Deprecated: Creation of dynamic property ArrayObject::$prop is deprecated in %s on line %d
array(3) {
[0]=>
Expand All @@ -26,6 +28,8 @@ array(3) {
int(3)
}

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Deprecated: Creation of dynamic property ArrayObject::$prop is deprecated in %s on line %d
array(1) {
["prop"]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ var_dump(new ArrayObject(array('key1' => 'val1')));
echo "--> Nested ArrayObject argument:\n";
var_dump(new ArrayObject(new ArrayObject($a)));
?>
--EXPECT--
--EXPECTF--
--> No arguments:
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
--> Object argument:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
object(stdClass)#1 (1) {
Expand All @@ -40,6 +42,10 @@ object(ArrayObject)#2 (1) {
}
}
--> Nested ArrayObject argument:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
object(ArrayObject)#3 (1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function testAccess($c, $ao) {
?>
--EXPECTF--
--> Access prop on instance of ArrayObject:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down Expand Up @@ -78,6 +80,8 @@ object(C)#1 (0) {
}

--> Access prop on instance of MyArrayObject:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function testAccess($c, $ao) {
?>
--EXPECTF--
--> Access prop on instance of ArrayObject with ArrayObject::STD_PROP_LIST:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down Expand Up @@ -78,6 +80,8 @@ object(C)#1 (0) {
}

--> Access prop on instance of MyArrayObject with ArrayObject::STD_PROP_LIST:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function testAccess($c, $ao) {
?>
--EXPECTF--
--> Access prop on instance of ArrayObject with ArrayObject::ARRAY_AS_PROPS:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down Expand Up @@ -76,6 +78,8 @@ object(C)#1 (0) {
}

--> Access prop on instance of MyArrayObject with ArrayObject::ARRAY_AS_PROPS:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function testAccess($c, $ao) {
?>
--EXPECTF--
--> Access prop on instance of ArrayObject with ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down Expand Up @@ -76,6 +78,8 @@ object(C)#1 (0) {
}

--> Access prop on instance of MyArrayObject with ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS:

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
- Iteration:
prop=>C::prop.orig
- Read:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ $ao = new ArrayObject($o);
$ao->asort();
var_dump($a, $o, $ao);
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
array(2) {
[0]=>
int(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ $ao1 = new ArrayObject($c);
var_dump($ao1->asort());
var_dump($ao1, $c);
?>
--EXPECT--
--EXPECTF--
*** Testing ArrayObject::asort() : basic functionality ***

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
bool(true)
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ $ao1['new.ao1'] = 'new element added to ao1';
$ao2['new.ao2'] = 'new element added to ao2';
var_dump($c, $ao1, $ao2);
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(C)#1 (3) {
["p1"]=>
string(32) "new prop added to c before clone"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ $clonedOuterArrayObject['new.coAO'] = 'new element added to $clonedOuterArrayObj

var_dump($wrappedObject, $innerArrayObject, $outerArrayObject, $clonedOuterArrayObject);
?>
--EXPECT--
--EXPECTF--
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
object(C)#1 (5) {
["p"]=>
string(9) "C::p.orig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ object(ArrayObject)#%d (1) {
}

--> exchangeArray(normal object):

Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
string(18) "normal object prop"
object(ArrayObject)#%d (1) {
["storage":"ArrayObject":private]=>
Expand All @@ -55,6 +57,8 @@ object(ArrayObject)#%d (1) {
}

--> exchangeArray(ArrayObject):

Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
string(19) "ArrayObject element"
object(ArrayObject)#%d (1) {
["storage":"ArrayObject":private]=>
Expand All @@ -68,6 +72,8 @@ object(ArrayObject)#%d (1) {
}

--> exchangeArray(ArrayIterator):

Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
string(21) "ArrayIterator element"
object(ArrayObject)#%d (1) {
["storage":"ArrayObject":private]=>
Expand All @@ -81,6 +87,10 @@ object(ArrayObject)#%d (1) {
}

--> exchangeArray(nested ArrayObject):

Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d

Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
string(26) "nested ArrayObject element"
object(ArrayObject)#%d (1) {
["storage":"ArrayObject":private]=>
Expand All @@ -94,4 +104,4 @@ object(ArrayObject)#%d (1) {
}
}
}
}
}
Loading