Open chibinz opened 1 day ago
Yeah, references …
It seems to me that we would need to "lock" the array during sort operations (and basically all others which take arrays as reference).
We could try increasing the refcount to cause separation on any modification of the array to prevent it from going away. That's essentially locking, by making sure the original array can't go away, be modified or moved. That said, implementing this I ran into some issues with the GC... GH-16654
Hmm, I'm not convinced that this is the right approach. After all, users manipulating an array during sorting (etc.) are probably doing something wrong. Instead of silently accepting these modifications without any effect, it would be better to inform users about their mistake (exception?)
And some manipulations might even be okay (I mean we're talking about references); we should avoid crashes, though.
Instead of silently accepting these modifications without any effect, it would be better to inform users about their mistake (exception?)
This might be optimal in terms of behavior, but it might not be simple to implement. E.g. where do we actually trigger the exception? Optimally, we would avoid checking if the array is locked for every modification. Instead, we may still add a refcount when the array is locked, and then only check on separation. However, that also means separation can now fail (without bailing), which would require all users of SEPARATE_ARRAY()
or zend_array_dup()
(depending on where we put it) to handle errors, for something that really should never happen.
@iluuu1994, indeed you're right. There is no really satifying solution. Thus I wrote:
Yeah, references …
Description
The following code:
Resulted in this output:
Requires
USE_ZEND_ALLOC=0
PHP Version
PHP 8.5.0-dev
Operating System
No response