-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PHP-8.1: Fix GH-8996: DOMNode serialization on PHP ^8.1 Fix GH-12380: JIT+private array property access inside closure accesses private property in child class
- Loading branch information
Showing
9 changed files
with
269 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
--TEST-- | ||
GH-8996: DOMNode serialization on PHP ^8.1 | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
echo "=== __sleep and __wakeup ===\n"; | ||
|
||
class SerializableDomDocumentSleepWakeup extends DOMDocument | ||
{ | ||
private $xmlData; | ||
|
||
public function __sleep(): array | ||
{ | ||
$this->xmlData = $this->saveXML(); | ||
return ['xmlData']; | ||
} | ||
|
||
public function __wakeup(): void | ||
{ | ||
$this->loadXML($this->xmlData); | ||
} | ||
} | ||
|
||
$dom = new SerializableDomDocumentSleepWakeup('1.0', 'UTF-8'); | ||
$dom->loadXML('<tag>value</tag>'); | ||
|
||
$serialized = serialize($dom); | ||
var_dump($serialized); | ||
$unserialized = unserialize($serialized); | ||
|
||
echo "Serialized:\n-----------\n$serialized\n-----------\nRestored:\n-----------\n{$unserialized->saveXml()}"; | ||
|
||
echo "=== __serialize and __unserialize ===\n"; | ||
|
||
class SerializableDomDocument__Serialize__Unserialize extends DOMDocument | ||
{ | ||
public function __serialize(): array | ||
{ | ||
return ['xmlData' => $this->saveXML()]; | ||
} | ||
|
||
public function __unserialize(array $data): void | ||
{ | ||
$this->loadXML($data['xmlData']); | ||
} | ||
} | ||
|
||
$dom = new SerializableDomDocument__Serialize__Unserialize('1.0', 'UTF-8'); | ||
$dom->loadXML('<tag>value</tag>'); | ||
|
||
$serialized = serialize($dom); | ||
$unserialized = unserialize($serialized); | ||
|
||
echo "Serialized:\n-----------\n$serialized\n-----------\nRestored:\n-----------\n{$unserialized->saveXml()}"; | ||
|
||
echo "=== serialize and unserialize ===\n"; | ||
|
||
class SerializableDomDocumentSerializeUnserialize extends DOMDocument implements Serializable | ||
{ | ||
public function serialize(): ?string | ||
{ | ||
return $this->saveXML(); | ||
} | ||
|
||
public function unserialize(string $data): void | ||
{ | ||
$this->loadXML($data); | ||
} | ||
} | ||
|
||
$dom = new SerializableDomDocumentSerializeUnserialize('1.0', 'UTF-8'); | ||
$dom->loadXML('<tag>value</tag>'); | ||
|
||
$serialized = serialize($dom); | ||
$unserialized = unserialize($serialized); | ||
|
||
echo "Serialized:\n-----------\n$serialized\n-----------\nRestored:\n-----------\n{$unserialized->saveXml()}"; | ||
|
||
?> | ||
--EXPECTF-- | ||
=== __sleep and __wakeup === | ||
string(144) "O:34:"SerializableDomDocumentSleepWakeup":1:{s:43:"%0SerializableDomDocumentSleepWakeup%0xmlData";s:39:"<?xml version="1.0"?> | ||
<tag>value</tag> | ||
";}" | ||
Serialized: | ||
----------- | ||
O:34:"SerializableDomDocumentSleepWakeup":1:{s:43:"%0SerializableDomDocumentSleepWakeup%0xmlData";s:39:"<?xml version="1.0"?> | ||
<tag>value</tag> | ||
";} | ||
----------- | ||
Restored: | ||
----------- | ||
<?xml version="1.0"?> | ||
<tag>value</tag> | ||
=== __serialize and __unserialize === | ||
Serialized: | ||
----------- | ||
O:47:"SerializableDomDocument__Serialize__Unserialize":1:{s:7:"xmlData";s:39:"<?xml version="1.0"?> | ||
<tag>value</tag> | ||
";} | ||
----------- | ||
Restored: | ||
----------- | ||
<?xml version="1.0"?> | ||
<tag>value</tag> | ||
=== serialize and unserialize === | ||
|
||
Deprecated: SerializableDomDocumentSerializeUnserialize implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d | ||
Serialized: | ||
----------- | ||
C:43:"SerializableDomDocumentSerializeUnserialize":39:{<?xml version="1.0"?> | ||
<tag>value</tag> | ||
} | ||
----------- | ||
Restored: | ||
----------- | ||
<?xml version="1.0"?> | ||
<tag>value</tag> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
DOM classes are not unserializable | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$classes = [ | ||
"DOMXPath", | ||
"DOMDocument", | ||
"DOMNode", | ||
"DOMNameSpaceNode", | ||
]; | ||
|
||
foreach ($classes as $class) | ||
{ | ||
try { | ||
unserialize('O:' . strlen($class) . ':"' . $class . '":0:{}'); | ||
} catch (Exception $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Unserialization of 'DOMXPath' is not allowed | ||
Unserialization of 'DOMDocument' is not allowed, unless unserialization methods are implemented in a subclass | ||
Unserialization of 'DOMNode' is not allowed, unless unserialization methods are implemented in a subclass | ||
Unserialization of 'DOMNameSpaceNode' is not allowed, unless unserialization methods are implemented in a subclass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--TEST-- | ||
GH-12380: JIT+private array property access inside closure accesses private property in child class | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.file_update_protection=0 | ||
opcache.jit_buffer_size=1M | ||
opcache.protect_memory=1 | ||
opcache.jit=tracing | ||
opcache.jit_hot_loop=1 | ||
opcache.jit_hot_func=1 | ||
opcache.jit_hot_return=1 | ||
opcache.jit_hot_side_exit=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--FILE-- | ||
<?php | ||
|
||
abstract class a | ||
{ | ||
private int $v = 1; | ||
|
||
public function test(): void | ||
{ | ||
var_dump($this->v); | ||
(function (): void { | ||
var_dump($this->v); | ||
})(); | ||
} | ||
} | ||
|
||
final class b extends a { | ||
private int $v = 0; | ||
} | ||
$a = new b; | ||
|
||
for ($i = 0; $i < 10; $i++) { | ||
$a->test(); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) |