1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

ext/standard/array.c: add tests when extracting negative keys

This commit is contained in:
Gina Peter Banyard
2025-11-16 22:14:15 +00:00
parent 095fd26c95
commit d026e2bca1
2 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
--TEST--
extract() with negative keys
--FILE--
<?php
$a = [-5 => 'hello', 'world', 2 => 'positive', 'check' => 'extracted'];
function foo(array $a) {
extract($a, EXTR_PREFIX_ALL, 'prefix');
var_dump(get_defined_vars());
}
foo($a);
?>
--EXPECT--
array(3) {
["a"]=>
array(4) {
[-5]=>
string(5) "hello"
[-4]=>
string(5) "world"
[2]=>
string(8) "positive"
["check"]=>
string(9) "extracted"
}
["prefix_2"]=>
string(8) "positive"
["prefix_check"]=>
string(9) "extracted"
}

View File

@@ -0,0 +1,11 @@
--TEST--
extract() with negative keys
--FILE--
<?php
$arr = [-1 => "foo"];
var_dump(extract($arr, EXTR_PREFIX_ALL | EXTR_REFS, "prefix"));
?>
--EXPECT--
int(0)