php-src/ext/ffi/tests/arrayPointer.phpt
Tyson Andre fe2dc2b481
Avoid crash for reset/end/next/prev() on ffi classes (#9711)
(And any PECLs returning `zend_empty_array` in the handler->get_properties
overrides)

Closes GH-9697

This is similar to the fix used in d9651a9419
for array_walk.

This should make it safer for php-src (and PECLs, long-term) to return
the empty immutable array in `handler->get_properties` to avoid wasting memory.
See https://github.com/php/php-src/issues/9697#issuecomment-1273613175

The only possible internal iterator position for the empty array is at the end
of the empty array (nInternalPointer=0).
The `zend_hash*del*` helpers will always set nInternalPointer to 0 when an
array becomes empty,
regardless of previous insertions/deletions/updates to the array.
2023-02-03 09:17:33 -05:00

21 lines
364 B
PHP

--TEST--
FFI: Test deprecated use of array helper functions on FFI classes doesn't crash
--EXTENSIONS--
ffi
--INI--
ffi.enable=1
--FILE--
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
$data = FFI::new('int');
var_dump(reset($data));
var_dump(end($data));
var_dump(next($data));
var_dump(prev($data));
?>
--EXPECTF--
bool(false)
bool(false)
bool(false)
bool(false)