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:
31
ext/standard/tests/array/extract_negative_keys.phpt
Normal file
31
ext/standard/tests/array/extract_negative_keys.phpt
Normal 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"
|
||||
}
|
||||
11
ext/standard/tests/array/extract_negative_keys2.phpt
Normal file
11
ext/standard/tests/array/extract_negative_keys2.phpt
Normal 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)
|
||||
Reference in New Issue
Block a user