mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
ext/spl: Deprecate ArrayObject and ArrayIterator with objects (#19420)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_arrayobject_and_arrayiterator_with_objects This also moves tests into a subfolder.
This commit is contained in:
committed by
GitHub
parent
9c754baa99
commit
fb87b14b6c
141
ext/spl/tests/ArrayObject/arrayObject_exchangeArray_basic3.phpt
Normal file
141
ext/spl/tests/ArrayObject/arrayObject_exchangeArray_basic3.phpt
Normal file
@@ -0,0 +1,141 @@
|
||||
--TEST--
|
||||
SPL: ArrayObject::exchangeArray() basic usage with object as underlying data store.
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
#%dAllowDynamicProperties]
|
||||
class C {
|
||||
public $pub1 = 'public1';
|
||||
}
|
||||
|
||||
echo "--> exchangeArray() with objects:\n";
|
||||
$original = new C;
|
||||
$ao = new ArrayObject($original);
|
||||
$swapIn = new C;
|
||||
try {
|
||||
$copy = $ao->exchangeArray($swapIn);
|
||||
$copy['addedToCopy'] = 'added To Copy';
|
||||
} catch (Exception $e) {
|
||||
echo "Exception:" . $e->getMessage() . "\n";
|
||||
}
|
||||
$swapIn->addedToSwapIn = 'added To Swap-In';
|
||||
$original->addedToOriginal = 'added To Original';
|
||||
var_dump($ao, $original, $swapIn, $copy);
|
||||
|
||||
|
||||
echo "\n\n--> exchangeArray() with no arg:\n";
|
||||
unset($original, $ao, $swapIn, $copy);
|
||||
$original = new C;
|
||||
$ao = new ArrayObject($original);
|
||||
try {
|
||||
$copy = $ao->exchangeArray();
|
||||
$copy['addedToCopy'] = 'added To Copy';
|
||||
} catch (TypeError $e) {
|
||||
echo "Exception: " . $e->getMessage() . "\n";
|
||||
}
|
||||
$original->addedToOriginal = 'added To Original';
|
||||
var_dump($ao, $original, $copy);
|
||||
|
||||
echo "\n\n--> exchangeArray() with bad arg type:\n";
|
||||
unset($original, $ao, $swapIn, $copy);
|
||||
$original = new C;
|
||||
$ao = new ArrayObject($original);
|
||||
try {
|
||||
$copy = $ao->exchangeArray(null);
|
||||
$copy['addedToCopy'] = 'added To Copy';
|
||||
} catch (TypeError $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
$original->addedToOriginal = 'added To Original';
|
||||
var_dump($ao, $original, $copy);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
--> exchangeArray() with objects:
|
||||
|
||||
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
|
||||
|
||||
Deprecated: Creation of dynamic property C::$addedToSwapIn is deprecated in %s on line %d
|
||||
|
||||
Deprecated: Creation of dynamic property C::$addedToOriginal is deprecated in %s on line %d
|
||||
object(ArrayObject)#2 (1) {
|
||||
["storage":"ArrayObject":private]=>
|
||||
object(C)#3 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToSwapIn"]=>
|
||||
string(16) "added To Swap-In"
|
||||
}
|
||||
}
|
||||
object(C)#1 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToOriginal"]=>
|
||||
string(17) "added To Original"
|
||||
}
|
||||
object(C)#3 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToSwapIn"]=>
|
||||
string(16) "added To Swap-In"
|
||||
}
|
||||
array(2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToCopy"]=>
|
||||
string(13) "added To Copy"
|
||||
}
|
||||
|
||||
|
||||
--> exchangeArray() with no arg:
|
||||
|
||||
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
|
||||
Exception: ArrayObject::exchangeArray() expects exactly 1 argument, 0 given
|
||||
|
||||
Deprecated: Creation of dynamic property C::$addedToOriginal is deprecated in %s on line %d
|
||||
|
||||
Warning: Undefined variable $copy in %s on line %d
|
||||
object(ArrayObject)#2 (1) {
|
||||
["storage":"ArrayObject":private]=>
|
||||
object(C)#3 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToOriginal"]=>
|
||||
string(17) "added To Original"
|
||||
}
|
||||
}
|
||||
object(C)#3 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToOriginal"]=>
|
||||
string(17) "added To Original"
|
||||
}
|
||||
NULL
|
||||
|
||||
|
||||
--> exchangeArray() with bad arg type:
|
||||
|
||||
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
|
||||
ArrayObject::exchangeArray(): Argument #1 ($array) must be of type array, null given
|
||||
|
||||
Deprecated: Creation of dynamic property C::$addedToOriginal is deprecated in %s on line %d
|
||||
|
||||
Warning: Undefined variable $copy in %s on line %d
|
||||
object(ArrayObject)#3 (1) {
|
||||
["storage":"ArrayObject":private]=>
|
||||
object(C)#2 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToOriginal"]=>
|
||||
string(17) "added To Original"
|
||||
}
|
||||
}
|
||||
object(C)#2 (2) {
|
||||
["pub1"]=>
|
||||
string(7) "public1"
|
||||
["addedToOriginal"]=>
|
||||
string(17) "added To Original"
|
||||
}
|
||||
NULL
|
||||
Reference in New Issue
Block a user