[php-src] Issue #8044: var_export emits debug assertion errors for `HT_ASSERT_RC1(ht);` in builds for SplFixedArray circular references

From: Date: Sat, 05 Feb 2022 21:12:34 +0000
Subject: [php-src] Issue #8044: var_export emits debug assertion errors for `HT_ASSERT_RC1(ht);` in builds for SplFixedArray circular references
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239507@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8044 Comment Author: TysonAndre It seems like the most commonly used extension (out of extensions with functionality similar to SplFixedArray) works around this/avoids this by implementing neither get_properties or get_properties_for for any classes, returning empty arrays. - Possibly not done to avoid this infinite recursion, possibly issues on finding documentation on the proper way to have get_properties/get_properties_for implemented (no code comments in php-src for this), possibly to save memory, or some combination of those issues (I didn't see anything in a quick search of var_export skimming the issue tracker) ```php php > $v = new Ds\Vector(); php > $v[] = 123; php > var_export($v); Ds\Vector::__set_state(array( )) php > var_dump($v); object(Ds\Vector)#2 (1) { [0]=> int(123) } php > var_export((array)$v); array ( ) ``` I was working on similar functionality. Except for the way infinite recursion is currently detected in var_export (fixed by the linked PR), it looks like it would be possible for PECLs/php-src modules to get var_export/array casts to work and keep the low memory usage (and also avoid delaying garbage collections by having duplicates in stale copies of the underlying collection in zend_object->properties)) by 1. Returning brand new arrays in get_properties_for for the caller to free 2. Returning the immutable empty array (zend_empty_array) in get_properties, similar to ext/ffi/ffi.c

« previous php.bugs (#239507) next »