mirror of
https://github.com/php/php-src.git
synced 2026-03-29 03:32:20 +02:00
* Emit deprecation warnings when adding dynamic properties to classes during unserialization - this will become an Error in php 9.0. (Adding dynamic properties in other contexts was already a deprecation warning - the use case of unserialization was overlooked) * Throw an error when attempting to add a dynamic property to a `readonly` class when unserializing * Add new serialization methods `__serialize`/`__unserialize` for SplFixedArray to avoid creating deprecated dynamic properties that would then be added to the backing fixed-size array * Don't add named dynamic/declared properties (e.g. $obj->foo) of SplFixedArray to the backing array when unserializing * Update tests to declare properties or to expect the deprecation warning * Add news entry Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
115 lines
2.3 KiB
PHP
115 lines
2.3 KiB
PHP
--TEST--
|
|
Bug #74669: Unserialize ArrayIterator broken
|
|
--FILE--
|
|
<?php
|
|
|
|
class Container implements Iterator
|
|
{
|
|
public $container;
|
|
public $iterator;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->container = new ArrayObject();
|
|
$this->iterator = $this->container->getIterator();
|
|
}
|
|
|
|
public function append($element)
|
|
{
|
|
$this->container->append($element);
|
|
}
|
|
|
|
public function current(): mixed
|
|
{
|
|
return $this->iterator->current();
|
|
}
|
|
|
|
public function next(): void
|
|
{
|
|
$this->iterator->next();
|
|
}
|
|
|
|
public function key(): mixed
|
|
{
|
|
return $this->iterator->key();
|
|
}
|
|
|
|
public function valid(): bool
|
|
{
|
|
return $this->iterator->valid();
|
|
}
|
|
|
|
public function rewind(): void
|
|
{
|
|
$this->iterator->rewind();
|
|
}
|
|
}
|
|
|
|
class SelfArray extends ArrayObject
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct($this);
|
|
}
|
|
}
|
|
|
|
$container = new Container();
|
|
$container->append('test1');
|
|
$container->append('test2');
|
|
$container->valid();
|
|
$serialized = serialize($container);
|
|
unset($container);
|
|
|
|
$container = unserialize($serialized);
|
|
|
|
foreach ($container as $key => $value) {
|
|
echo $key . ' => ' . $value . PHP_EOL;
|
|
}
|
|
|
|
$arObj = new ArrayObject(['test1', 'test2']);
|
|
$serialized = serialize($container);
|
|
unset($arObj);
|
|
|
|
$arObj = unserialize($serialized);
|
|
foreach($arObj as $key => $value) {
|
|
echo $key . ' => ' . $value . PHP_EOL;
|
|
}
|
|
|
|
$payload = 'x:i:33554432;O:8:"stdClass":0:{};m:a:0:{}';
|
|
$str = 'C:11:"ArrayObject":' . strlen($payload) . ':{' . $payload . '}';
|
|
|
|
$ao = unserialize($str);
|
|
var_dump($ao['foo']);
|
|
|
|
$selfArray = new SelfArray();
|
|
$selfArray['foo'] = 'bar';
|
|
var_dump($selfArray);
|
|
$serialized = serialize($selfArray);
|
|
var_dump($serialized);
|
|
unset($selfArray);
|
|
$selfArray = unserialize($serialized);
|
|
var_dump($selfArray);
|
|
var_dump($selfArray['foo']);
|
|
|
|
?>
|
|
--EXPECTF--
|
|
0 => test1
|
|
1 => test2
|
|
0 => test1
|
|
1 => test2
|
|
|
|
Warning: Undefined array key "foo" in %s on line %d
|
|
NULL
|
|
object(SelfArray)#9 (1) {
|
|
["foo"]=>
|
|
string(3) "bar"
|
|
}
|
|
string(77) "O:9:"SelfArray":4:{i:0;i:16777216;i:1;N;i:2;a:1:{s:3:"foo";s:3:"bar";}i:3;N;}"
|
|
|
|
Deprecated: Creation of dynamic property SelfArray::$foo is deprecated in %s on line %d
|
|
object(SelfArray)#9 (1) {
|
|
["foo"]=>
|
|
string(3) "bar"
|
|
}
|
|
string(3) "bar"
|