-
Notifications
You must be signed in to change notification settings - Fork 8.1k
serializer: more unserialize_callback_func INI tests and fix #22933
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
Merged
Girgias
merged 3 commits into
php:master
from
Girgias:2026-07-unserialize_callback_func-tests
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
...rd/tests/serialize/unserialize_callback_func/deprecated_partially_supported_callable.phpt
This file contains hidden or 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,51 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with partially deprecated callable string | ||
| --INI-- | ||
| unserialize_callback_func=parent::my_unserialize | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class TesterParent { | ||
| public static function my_unserialize($name) { | ||
| echo 'callback_called in ', __CLASS__ , PHP_EOL; | ||
| eval('class Foo {}'); | ||
| } | ||
| } | ||
|
|
||
| class TesterChild extends TesterParent { | ||
| public static function my_unserialize($name) { | ||
| echo 'callback_called in ', __CLASS__ , PHP_EOL; | ||
| eval('class Foo {}'); | ||
| } | ||
|
|
||
| public function unserialize(string $str) { | ||
| return unserialize($str); | ||
| } | ||
| } | ||
|
|
||
| $s = 'O:3:"FOO":0:{}'; | ||
| try { | ||
| $o = unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| $tester = new TesterChild(); | ||
| $o = $tester->unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
| echo "Done"; | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Error: Invalid callback parent::my_unserialize, cannot access "parent" when no class scope is active | ||
|
|
||
| Deprecated: Use of "parent" in callables is deprecated in %s on line %d | ||
| callback_called in TesterParent | ||
| object(Foo)#3 (0) { | ||
| } | ||
| Done |
22 changes: 22 additions & 0 deletions
22
ext/standard/tests/serialize/unserialize_callback_func/fn_with_fqn.phpt
This file contains hidden or 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,22 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with fully qualified name function | ||
| --INI-- | ||
| unserialize_callback_func=\my_global_fn | ||
| --FILE-- | ||
| <?php | ||
| function my_global_fn($name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
|
|
||
| $o = unserialize('O:3:"FOO":0:{}'); | ||
|
|
||
| var_dump($o); | ||
|
|
||
| echo "Done"; | ||
| ?> | ||
| --EXPECT-- | ||
| callback_called | ||
| object(Foo)#1 (0) { | ||
| } | ||
| Done |
26 changes: 26 additions & 0 deletions
26
ext/standard/tests/serialize/unserialize_callback_func/fn_with_fqn_namespace.phpt
This file contains hidden or 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,26 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with fully qualified named namespaced function | ||
| --INI-- | ||
| unserialize_callback_func=\php\test\my_global_fn | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| namespace php\test { | ||
| function my_global_fn($name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
| } | ||
| namespace { | ||
| $o = unserialize('O:3:"FOO":0:{}'); | ||
|
|
||
| var_dump($o); | ||
|
|
||
| echo "Done"; | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| callback_called | ||
| object(Foo)#1 (0) { | ||
| } | ||
| Done |
25 changes: 25 additions & 0 deletions
25
ext/standard/tests/serialize/unserialize_callback_func/fn_with_null_bytes.phpt
This file contains hidden or 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,25 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with function name containing null bytes | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| ini_set('unserialize_callback_func', "foo\0butno"); | ||
|
|
||
| function foo(string $name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
|
|
||
| $s = 'O:3:"FOO":0:{}'; | ||
| try { | ||
| $o = unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| echo "Done"; | ||
| ?> | ||
| --EXPECT-- | ||
| Error: Invalid callback foo, function "foo" not found or invalid function name | ||
| Done |
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
ext/standard/tests/serialize/unserialize_callback_func/non_static_method_private.phpt
This file contains hidden or 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,42 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with private non-static method | ||
| --INI-- | ||
| unserialize_callback_func=Tester::my_unserialize | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class Tester { | ||
| private function my_unserialize($name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
|
|
||
| public function unserialize(string $str) { | ||
| return unserialize($str); | ||
| } | ||
| } | ||
|
|
||
| $s = 'O:3:"FOO":0:{}'; | ||
| try { | ||
| $o = unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| $tester = new Tester(); | ||
| $o = $tester->unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
| echo "Done"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Error: Invalid callback Tester::my_unserialize, non-static method Tester::my_unserialize() cannot be called statically | ||
| callback_called | ||
| object(Foo)#3 (0) { | ||
| } | ||
| Done |
42 changes: 42 additions & 0 deletions
42
ext/standard/tests/serialize/unserialize_callback_func/non_static_method_public.phpt
This file contains hidden or 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,42 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with public non-static method | ||
| --INI-- | ||
| unserialize_callback_func=Tester::my_unserialize | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class Tester { | ||
| public function my_unserialize($name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
|
|
||
| public function unserialize(string $str) { | ||
| return unserialize($str); | ||
| } | ||
| } | ||
|
|
||
| $s = 'O:3:"FOO":0:{}'; | ||
| try { | ||
| $o = unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| $tester = new Tester(); | ||
| $o = $tester->unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
| echo "Done"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Error: Invalid callback Tester::my_unserialize, non-static method Tester::my_unserialize() cannot be called statically | ||
| callback_called | ||
| object(Foo)#3 (0) { | ||
| } | ||
| Done |
26 changes: 26 additions & 0 deletions
26
ext/standard/tests/serialize/unserialize_callback_func/static_method.phpt
This file contains hidden or 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,26 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with public static method | ||
| --INI-- | ||
| unserialize_callback_func=Tester::my_unserialize | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class Tester { | ||
| public static function my_unserialize($name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
| } | ||
|
|
||
| $o = unserialize('O:3:"FOO":0:{}'); | ||
|
|
||
| var_dump($o); | ||
|
|
||
| echo "Done"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| callback_called | ||
| object(Foo)#1 (0) { | ||
| } | ||
| Done |
41 changes: 41 additions & 0 deletions
41
ext/standard/tests/serialize/unserialize_callback_func/static_method_private.phpt
This file contains hidden or 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,41 @@ | ||
| --TEST-- | ||
| unserialize_callback_func with private static method | ||
| --INI-- | ||
| unserialize_callback_func=Tester::my_unserialize | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class Tester { | ||
| private static function my_unserialize($name) { | ||
| echo "callback_called\n"; | ||
| eval('class Foo {}'); | ||
| } | ||
|
|
||
| public static function unserialize(string $str) { | ||
| return unserialize($str); | ||
| } | ||
| } | ||
|
|
||
| $s = 'O:3:"FOO":0:{}'; | ||
| try { | ||
| $o = unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| try { | ||
| $o = Tester::unserialize($s); | ||
| var_dump($o); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
| } | ||
| echo "Done"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Error: Invalid callback Tester::my_unserialize, cannot access private method Tester::my_unserialize() | ||
| callback_called | ||
| object(Foo)#2 (0) { | ||
| } | ||
| Done |
File renamed without changes.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.