1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/ext/spl/tests/SplFixedArray_immediate_gc.phpt
Tyson Andre c4ecd82f93 Make inspecting SplFixedArray instances more memory efficient/consistent, change print_r null props handling (#9757)
* Make handling of SplFixedArray properties more consistent

Create a brand new reference counted array every time in SplFixedArray
to be freed by the callers (or return null).
Switch from overriding `get_properties` to overriding `get_properties_for` handler

* Print objects with null hash table like others in print_r

Noticed when working on subsequent commits for SplFixedArray.
Make whether zend_get_properties_for returns null or an empty array
invisible to the end user - it would be always be a non-null array for
user-defined classes.
Always print newlines with `\n\s*(\n\s*)` after objects

Noticed when working on SplFixedArray changes, e.g. in
ext/spl/tests/SplFixedArray__construct_param_null.phpt
2022-10-24 08:33:25 -04:00

36 lines
787 B
PHP

--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) {
}