1
0

提交代码

This commit is contained in:
2020-08-06 14:50:07 +08:00
parent 9d0d5f4be9
commit d7a848c824
11299 changed files with 1321854 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\ConcreteClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\ConcreteClass')),
],
null,
[
'Symfony\\Component\\VarExporter\\Tests\\AbstractClass' => [
'foo' => [
123,
],
'bar' => [
234,
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,22 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['ArrayIterator'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayIterator')),
],
null,
[
'ArrayIterator' => [
"\0" => [
[
[
123,
],
1,
],
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,19 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['ArrayIterator'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayIterator')),
],
null,
[],
$o[0],
[
[
1,
[
123,
],
[],
],
]
);

View File

@@ -0,0 +1,22 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyArrayObject')),
],
null,
[
'ArrayObject' => [
"\0" => [
[
[
234,
],
1,
],
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,21 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyArrayObject')),
],
null,
[],
$o[0],
[
[
1,
[
234,
],
[
"\0".'Symfony\\Component\\VarExporter\\Tests\\MyArrayObject'."\0".'unused' => 123,
],
],
]
);

View File

@@ -0,0 +1,29 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
clone $p['ArrayObject'],
],
null,
[
'ArrayObject' => [
"\0" => [
[
[
1,
$o[0],
],
0,
],
],
],
'stdClass' => [
'foo' => [
$o[1],
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,28 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['ArrayObject'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('ArrayObject')),
clone $p['ArrayObject'],
],
null,
[],
$o[0],
[
[
0,
[
1,
$o[0],
],
[
'foo' => $o[1],
],
],
-1 => [
0,
[],
[],
],
]
);

View File

@@ -0,0 +1,3 @@
<?php
return true;

View File

@@ -0,0 +1,15 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
(($f = &\Symfony\Component\VarExporter\Internal\Registry::$factories)['Symfony\\Component\\VarExporter\\Tests\\MyCloneable'] ?? \Symfony\Component\VarExporter\Internal\Registry::f('Symfony\\Component\\VarExporter\\Tests\\MyCloneable'))(),
($f['Symfony\\Component\\VarExporter\\Tests\\MyNotCloneable'] ?? \Symfony\Component\VarExporter\Internal\Registry::f('Symfony\\Component\\VarExporter\\Tests\\MyNotCloneable'))(),
],
null,
[],
[
$o[0],
$o[1],
],
[]
);

View File

@@ -0,0 +1,25 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['DateTime'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('DateTime')),
],
null,
[
'stdClass' => [
'date' => [
'1970-01-01 00:00:00.000000',
],
'timezone_type' => [
1,
],
'timezone' => [
'+00:00',
],
],
],
$o[0],
[
1 => 0,
]
);

View File

@@ -0,0 +1,30 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
(\Symfony\Component\VarExporter\Internal\Registry::$factories['Error'] ?? \Symfony\Component\VarExporter\Internal\Registry::f('Error'))(),
],
null,
[
'TypeError' => [
'file' => [
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
],
'line' => [
234,
],
],
'Error' => [
'trace' => [
[
'file' => \dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
'line' => 123,
],
],
],
],
$o[0],
[
1 => 0,
]
);

View File

@@ -0,0 +1,7 @@
<?php
return [
[
123,
],
];

View File

@@ -0,0 +1,11 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
'C:54:"Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator":49:{a:2:{i:0;i:123;i:1;s:21:"x:i:0;a:0:{};m:a:0:{}";}}',
]),
null,
[],
$o[0],
[]
);

View File

@@ -0,0 +1,17 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\FinalArrayIterator')),
],
null,
[],
$o[0],
[
[
0,
[],
[],
],
]
);

View File

@@ -0,0 +1,27 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
'O:46:"Symfony\\Component\\VarExporter\\Tests\\FinalError":1:{s:12:"'."\0".'Error'."\0".'trace";a:0:{}}',
]),
null,
[
'TypeError' => [
'file' => [
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
],
'line' => [
123,
],
],
'Error' => [
'trace' => [
[],
],
],
],
$o[0],
[
1 => 0,
]
);

View File

@@ -0,0 +1,27 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
(\Symfony\Component\VarExporter\Internal\Registry::$factories['Symfony\\Component\\VarExporter\\Tests\\FinalError'] ?? \Symfony\Component\VarExporter\Internal\Registry::f('Symfony\\Component\\VarExporter\\Tests\\FinalError'))(),
],
null,
[
'TypeError' => [
'file' => [
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
],
'line' => [
123,
],
],
'Error' => [
'trace' => [
[],
],
],
],
$o[0],
[
1 => 0,
]
);

View File

@@ -0,0 +1,11 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
(\Symfony\Component\VarExporter\Internal\Registry::$factories['Symfony\\Component\\VarExporter\\Tests\\FinalStdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::f('Symfony\\Component\\VarExporter\\Tests\\FinalStdClass'))(),
],
null,
[],
$o[0],
[]
);

View File

@@ -0,0 +1,11 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
'C:51:"Symfony\\Component\\VarExporter\\Tests\\FooSerializable":20:{a:1:{i:0;s:3:"bar";}}',
]),
null,
[],
$o[0],
[]
);

View File

@@ -0,0 +1,16 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [],
[
$r = [],
$r[1] = [
&$r[1],
],
],
[],
[
&$r[1],
],
[]
);

View File

@@ -0,0 +1,18 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
],
[
$r = [],
$r[1] = $o[0],
],
[],
[
&$r[1],
&$r[1],
$o[0],
],
[]
);

View File

@@ -0,0 +1,11 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
'O:20:"SomeNotExistingClass":0:{}',
]),
null,
[],
$o[0],
[]
);

View File

@@ -0,0 +1,8 @@
<?php
return [
"\0\0\r\n"
.'A' => 'B'."\r"
.'C'."\n"
."\n",
];

View File

@@ -0,0 +1,8 @@
<?php
return [
5 => true,
1 => true,
2 => true,
true,
];

View File

@@ -0,0 +1,16 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\Php74Serializable'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\Php74Serializable')),
clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
],
null,
[],
$o[0],
[
[
$o[1],
],
]
);

View File

@@ -0,0 +1,17 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\PrivateConstructor'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\PrivateConstructor')),
],
null,
[
'stdClass' => [
'prop' => [
'bar',
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,26 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue')),
clone ($p['Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue')),
],
null,
[
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [
'prot' => [
123,
123,
],
'priv' => [
234,
234,
],
],
],
[
$o[0],
$o[1],
],
[]
);

View File

@@ -0,0 +1,14 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = \Symfony\Component\VarExporter\Internal\Registry::unserialize([], [
'C:50:"Symfony\\Component\\VarExporter\\Tests\\MySerializable":3:{123}',
]),
null,
[],
[
$o[0],
$o[0],
],
[]
);

View File

@@ -0,0 +1,8 @@
<?php
return [
123,
[
'abc',
],
];

View File

@@ -0,0 +1,21 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['SplObjectStorage'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('SplObjectStorage')),
clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
],
null,
[
'SplObjectStorage' => [
"\0" => [
[
$o[1],
345,
],
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,20 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['SplObjectStorage'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('SplObjectStorage')),
clone ($p['stdClass'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('stdClass')),
],
null,
[],
$o[0],
[
[
[
$o[1],
345,
],
[],
],
]
);

View File

@@ -0,0 +1,17 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\GoodNight'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\GoodNight')),
],
null,
[
'stdClass' => [
'good' => [
'night',
],
],
],
$o[0],
[]
);

View File

@@ -0,0 +1,13 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (\Symfony\Component\VarExporter\Internal\Registry::$prototypes['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyWakeup')),
],
null,
[],
$o[0],
[
1 => 0,
]
);

View File

@@ -0,0 +1,25 @@
<?php
return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
$o = [
clone (($p = &\Symfony\Component\VarExporter\Internal\Registry::$prototypes)['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'] ?? \Symfony\Component\VarExporter\Internal\Registry::p('Symfony\\Component\\VarExporter\\Tests\\MyWakeup')),
clone $p['Symfony\\Component\\VarExporter\\Tests\\MyWakeup'],
],
null,
[
'stdClass' => [
'sub' => [
$o[1],
123,
],
'baz' => [
1 => 123,
],
],
],
$o[0],
[
1 => 1,
0,
]
);

View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\VarExporter\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarExporter\Instantiator;
class InstantiatorTest extends TestCase
{
public function testNotFoundClass()
{
$this->expectException('Symfony\Component\VarExporter\Exception\ClassNotFoundException');
$this->expectExceptionMessage('Class "SomeNotExistingClass" not found.');
Instantiator::instantiate('SomeNotExistingClass');
}
/**
* @dataProvider provideFailingInstantiation
*/
public function testFailingInstantiation(string $class)
{
$this->expectException('Symfony\Component\VarExporter\Exception\NotInstantiableTypeException');
$this->expectExceptionMessageRegExp('/Type ".*" is not instantiable\./');
Instantiator::instantiate($class);
}
public function provideFailingInstantiation()
{
yield ['ReflectionClass'];
yield ['SplHeap'];
yield ['Throwable'];
yield ['Closure'];
yield ['SplFileInfo'];
}
public function testInstantiate()
{
$this->assertEquals((object) ['p' => 123], Instantiator::instantiate('stdClass', ['p' => 123]));
$this->assertEquals((object) ['p' => 123], Instantiator::instantiate('STDcLASS', ['p' => 123]));
$this->assertEquals(new \ArrayObject([123]), Instantiator::instantiate(\ArrayObject::class, ["\0" => [[123]]]));
$expected = [
"\0".__NAMESPACE__."\Bar\0priv" => 123,
"\0".__NAMESPACE__."\Foo\0priv" => 234,
];
$this->assertSame($expected, (array) Instantiator::instantiate(Bar::class, ['priv' => 123], [Foo::class => ['priv' => 234]]));
$e = Instantiator::instantiate('Exception', ['foo' => 123, 'trace' => [234]]);
$this->assertSame(123, $e->foo);
$this->assertSame([234], $e->getTrace());
}
}
class Foo
{
private $priv;
}
class Bar extends Foo
{
private $priv;
}

View File

@@ -0,0 +1,427 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\VarExporter\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
use Symfony\Component\VarExporter\Internal\Registry;
use Symfony\Component\VarExporter\VarExporter;
class VarExporterTest extends TestCase
{
use VarDumperTestTrait;
public function testPhpIncompleteClassesAreForbidden()
{
$this->expectException('Symfony\Component\VarExporter\Exception\ClassNotFoundException');
$this->expectExceptionMessage('Class "SomeNotExistingClass" not found.');
$unserializeCallback = ini_set('unserialize_callback_func', 'var_dump');
try {
Registry::unserialize([], ['O:20:"SomeNotExistingClass":0:{}']);
} finally {
$this->assertSame('var_dump', ini_set('unserialize_callback_func', $unserializeCallback));
}
}
/**
* @dataProvider provideFailingSerialization
*/
public function testFailingSerialization($value)
{
$this->expectException('Symfony\Component\VarExporter\Exception\NotInstantiableTypeException');
$this->expectExceptionMessageRegExp('/Type ".*" is not instantiable\./');
$expectedDump = $this->getDump($value);
try {
VarExporter::export($value);
} finally {
$this->assertDumpEquals(rtrim($expectedDump), $value);
}
}
public function provideFailingSerialization()
{
yield [hash_init('md5')];
yield [new \ReflectionClass('stdClass')];
yield [(new \ReflectionFunction(function (): int {}))->getReturnType()];
yield [new \ReflectionGenerator((function () { yield 123; })())];
yield [function () {}];
yield [function () { yield 123; }];
yield [new \SplFileInfo(__FILE__)];
yield [$h = fopen(__FILE__, 'r')];
yield [[$h]];
$a = new class() {
};
yield [$a];
$a = [null, $h];
$a[0] = &$a;
yield [$a];
}
/**
* @dataProvider provideExport
*/
public function testExport(string $testName, $value, bool $staticValueExpected = false)
{
$dumpedValue = $this->getDump($value);
$isStaticValue = true;
$marshalledValue = VarExporter::export($value, $isStaticValue);
$this->assertSame($staticValueExpected, $isStaticValue);
if ('var-on-sleep' !== $testName && 'php74-serializable' !== $testName) {
$this->assertDumpEquals($dumpedValue, $value);
}
$dump = "<?php\n\nreturn ".$marshalledValue.";\n";
$dump = str_replace(var_export(__FILE__, true), "\\dirname(__DIR__).\\DIRECTORY_SEPARATOR.'VarExporterTest.php'", $dump);
if (\PHP_VERSION_ID < 70400 && \in_array($testName, ['array-object', 'array-iterator', 'array-object-custom', 'spl-object-storage', 'final-array-iterator', 'final-error'], true)) {
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'-legacy.php';
} else {
$fixtureFile = __DIR__.'/Fixtures/'.$testName.'.php';
}
$this->assertStringEqualsFile($fixtureFile, $dump);
if ('incomplete-class' === $testName || 'external-references' === $testName) {
return;
}
$marshalledValue = include $fixtureFile;
if (!$isStaticValue) {
if ($value instanceof MyWakeup) {
$value->bis = null;
}
$this->assertDumpEquals($value, $marshalledValue);
} else {
$this->assertSame($value, $marshalledValue);
}
}
public function provideExport()
{
yield ['multiline-string', ["\0\0\r\nA" => "B\rC\n\n"], true];
yield ['bool', true, true];
yield ['simple-array', [123, ['abc']], true];
yield ['partially-indexed-array', [5 => true, 1 => true, 2 => true, 6 => true], true];
yield ['datetime', \DateTime::createFromFormat('U', 0)];
$value = new \ArrayObject();
$value[0] = 1;
$value->foo = new \ArrayObject();
$value[1] = $value;
yield ['array-object', $value];
yield ['array-iterator', new \ArrayIterator([123], 1)];
yield ['array-object-custom', new MyArrayObject([234])];
$value = new MySerializable();
yield ['serializable', [$value, $value]];
$value = new MyWakeup();
$value->sub = new MyWakeup();
$value->sub->sub = 123;
$value->sub->bis = 123;
$value->sub->baz = 123;
yield ['wakeup', $value];
yield ['clone', [new MyCloneable(), new MyNotCloneable()]];
yield ['private', [new MyPrivateValue(123, 234), new MyPrivateChildValue(123, 234)]];
$value = new \SplObjectStorage();
$value[new \stdClass()] = 345;
yield ['spl-object-storage', $value];
yield ['incomplete-class', unserialize('O:20:"SomeNotExistingClass":0:{}')];
$value = [(object) []];
$value[1] = &$value[0];
$value[2] = $value[0];
yield ['hard-references', $value];
$value = [];
$value[0] = &$value;
yield ['hard-references-recursive', $value];
static $value = [123];
yield ['external-references', [&$value], true];
unset($value);
$value = new \Error();
$rt = new \ReflectionProperty('Error', 'trace');
$rt->setAccessible(true);
$rt->setValue($value, ['file' => __FILE__, 'line' => 123]);
$rl = new \ReflectionProperty('Error', 'line');
$rl->setAccessible(true);
$rl->setValue($value, 234);
yield ['error', $value];
yield ['var-on-sleep', new GoodNight()];
$value = new FinalError(false);
$rt->setValue($value, []);
$rl->setValue($value, 123);
yield ['final-error', $value];
yield ['final-array-iterator', new FinalArrayIterator()];
yield ['final-stdclass', new FinalStdClass()];
$value = new MyWakeup();
$value->bis = new \ReflectionClass($value);
yield ['wakeup-refl', $value];
yield ['abstract-parent', new ConcreteClass()];
yield ['foo-serializable', new FooSerializable('bar')];
yield ['private-constructor', PrivateConstructor::create('bar')];
yield ['php74-serializable', new Php74Serializable()];
}
}
class MySerializable implements \Serializable
{
public function serialize()
{
return '123';
}
public function unserialize($data)
{
// no-op
}
}
class MyWakeup
{
public $sub;
public $bis;
public $baz;
public $def = 234;
public function __sleep()
{
return ['sub', 'baz'];
}
public function __wakeup()
{
if (123 === $this->sub) {
$this->bis = 123;
$this->baz = 123;
}
}
}
class MyCloneable
{
public function __clone()
{
throw new \Exception('__clone should never be called');
}
}
class MyNotCloneable
{
private function __clone()
{
throw new \Exception('__clone should never be called');
}
}
class PrivateConstructor
{
public $prop;
public static function create($prop): self
{
return new self($prop);
}
private function __construct($prop)
{
$this->prop = $prop;
}
}
class MyPrivateValue
{
protected $prot;
private $priv;
public function __construct($prot, $priv)
{
$this->prot = $prot;
$this->priv = $priv;
}
}
class MyPrivateChildValue extends MyPrivateValue
{
}
class MyArrayObject extends \ArrayObject
{
private $unused = 123;
public function __construct(array $array)
{
parent::__construct($array, 1);
}
public function setFlags($flags)
{
throw new \BadMethodCallException('Calling MyArrayObject::setFlags() is forbidden');
}
}
class GoodNight
{
public function __sleep()
{
$this->good = 'night';
return ['good'];
}
}
final class FinalError extends \Error
{
public function __construct(bool $throw = true)
{
if ($throw) {
throw new \BadMethodCallException('Should not be called.');
}
}
}
final class FinalArrayIterator extends \ArrayIterator
{
public function serialize()
{
return serialize([123, parent::serialize()]);
}
public function unserialize($data)
{
if ('' === $data) {
throw new \InvalidArgumentException('Serialized data is empty.');
}
list(, $data) = unserialize($data);
parent::unserialize($data);
}
}
final class FinalStdClass extends \stdClass
{
public function __clone()
{
throw new \BadMethodCallException('Should not be called.');
}
}
abstract class AbstractClass
{
protected $foo;
private $bar;
protected function setBar($bar)
{
$this->bar = $bar;
}
}
class ConcreteClass extends AbstractClass
{
public function __construct()
{
$this->foo = 123;
$this->setBar(234);
}
}
class FooSerializable implements \Serializable
{
private $foo;
public function __construct(string $foo)
{
$this->foo = $foo;
}
public function getFoo(): string
{
return $this->foo;
}
public function serialize(): string
{
return serialize([$this->getFoo()]);
}
public function unserialize($str)
{
list($this->foo) = unserialize($str);
}
}
class Php74Serializable implements \Serializable
{
public function __serialize()
{
return [$this->foo = new \stdClass()];
}
public function __unserialize(array $data)
{
list($this->foo) = $data;
}
public function __sleep()
{
throw new \BadMethodCallException();
}
public function __wakeup()
{
throw new \BadMethodCallException();
}
public function serialize()
{
throw new \BadMethodCallException();
}
public function unserialize($ser)
{
throw new \BadMethodCallException();
}
}