-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Make inspecting SplFixedArray instances more memory efficient/consistent, change print_r null props handling #9757
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
Merged
Changes from all commits
Commits
Show all changes
2 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
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
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,28 @@ | ||
--TEST-- | ||
SplFixedArray properties is compatible with ArrayObject | ||
--FILE-- | ||
<?php | ||
$ao = new ArrayObject([1, 2, 3]); | ||
$fixedArray = new SplFixedArray(1); | ||
$fixedArray[0] = new SplDoublyLinkedList(); | ||
$ao->exchangeArray($fixedArray); | ||
$ao[0] = new stdClass(); | ||
var_dump($ao); | ||
?> | ||
--EXPECT-- | ||
object(ArrayObject)#1 (1) { | ||
["storage":"ArrayObject":private]=> | ||
object(SplFixedArray)#2 (2) { | ||
[0]=> | ||
object(SplDoublyLinkedList)#3 (2) { | ||
["flags":"SplDoublyLinkedList":private]=> | ||
int(0) | ||
["dllist":"SplDoublyLinkedList":private]=> | ||
array(0) { | ||
} | ||
} | ||
["0"]=> | ||
object(stdClass)#4 (0) { | ||
} | ||
} | ||
} |
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,86 @@ | ||
--TEST-- | ||
SplFixedArray - get_properties_for handlers | ||
--FILE-- | ||
<?php | ||
#[AllowDynamicProperties] | ||
class MySplFixedArray extends SplFixedArray { | ||
public $x; | ||
public int $y; | ||
} | ||
class X {} | ||
class Y {} | ||
$array = new MySplFixedArray(2); | ||
var_dump(get_mangled_object_vars($array)); | ||
$array[0] = new stdClass(); | ||
$array[1] = new Y(); | ||
$array->x = new SplFixedArray(); | ||
$array->{0} = new X(); | ||
var_dump($array); | ||
// As of php 8.3, get_mangled_object_vars only contains object properties (dynamic properties and declared subclass properties) | ||
// (Array elements in the SplFixedArray are deliberately excluded) | ||
// Before php 8.3, this would have array elements get removed in some cases but not others. | ||
var_dump(get_mangled_object_vars($array)); | ||
echo "cast to array\n"; | ||
var_dump((array)$array); // Adds the values from the underlying array, then the declared/dynamic object properties | ||
echo json_encode($array), "\n"; // From JsonSerializable::serialize() | ||
$ser = serialize($array); | ||
echo "$ser\n"; | ||
// NOTE: The unserialize behavior for the property that is the string '0' is just because unserialize() | ||
// is coercing '0' to a string before calling SplFixedArray::__unserialize. | ||
// | ||
// Typical code would not use 0 as a property name, this test is just testing edge cases have proper reference counting and so on. | ||
var_dump(unserialize($ser)); | ||
?> | ||
--EXPECT-- | ||
array(1) { | ||
["x"]=> | ||
NULL | ||
} | ||
object(MySplFixedArray)#1 (4) { | ||
[0]=> | ||
object(stdClass)#2 (0) { | ||
} | ||
[1]=> | ||
object(Y)#3 (0) { | ||
} | ||
["x"]=> | ||
object(SplFixedArray)#4 (0) { | ||
} | ||
["0"]=> | ||
object(X)#5 (0) { | ||
} | ||
} | ||
array(2) { | ||
["x"]=> | ||
object(SplFixedArray)#4 (0) { | ||
} | ||
[0]=> | ||
object(X)#5 (0) { | ||
} | ||
} | ||
cast to array | ||
array(3) { | ||
[0]=> | ||
object(X)#5 (0) { | ||
} | ||
[1]=> | ||
object(Y)#3 (0) { | ||
} | ||
["x"]=> | ||
object(SplFixedArray)#4 (0) { | ||
} | ||
} | ||
[{},{}] | ||
O:15:"MySplFixedArray":5:{i:0;O:8:"stdClass":0:{}i:1;O:1:"Y":0:{}s:1:"x";i:0;s:1:"y";i:0;s:1:"0";O:1:"X":0:{}} | ||
object(MySplFixedArray)#6 (4) { | ||
[0]=> | ||
object(X)#9 (0) { | ||
} | ||
[1]=> | ||
object(Y)#8 (0) { | ||
} | ||
["x"]=> | ||
int(0) | ||
["y"]=> | ||
int(0) | ||
} |
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,35 @@ | ||
--TEST-- | ||
SplFixedArray - values should be gced after var_export then being modified | ||
--FILE-- | ||
<?php | ||
class HasDestructor { | ||
public function __destruct() { | ||
echo "In destructor\n"; | ||
} | ||
} | ||
$array = SplFixedArray::fromArray([new HasDestructor()]); | ||
var_dump($array); | ||
echo "Replacing\n"; | ||
$array[0] = new stdClass(); | ||
// As of php 8.3, this will be freed before the var_dump call | ||
echo "Dumping again\n"; | ||
var_dump($array); | ||
// As of php 8.3, this only contain object properties (dynamic properties and declared subclass properties) | ||
var_dump(get_mangled_object_vars($array)); | ||
?> | ||
--EXPECT-- | ||
object(SplFixedArray)#2 (1) { | ||
[0]=> | ||
object(HasDestructor)#1 (0) { | ||
} | ||
} | ||
Replacing | ||
In destructor | ||
Dumping again | ||
object(SplFixedArray)#2 (1) { | ||
[0]=> | ||
object(stdClass)#3 (0) { | ||
} | ||
} | ||
array(0) { | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArrayObject checks if get_properties_handler is overloaded and throws if it is.
After my change to spl_fixedarray.c, the get_properties handler of SplFixedArray is no longer overloaded.
So I changed to DateInterval, which continues to overload the get_properties handler