php-src/Zend/tests/list_keyed.phpt

72 lines
1.4 KiB
Plaintext
Raw Normal View History

Allow specifying keys on list() elements Squashed commit of the following: commit 0361dbe35616722fbe51b446ab7b43a9ca01f455 Author: Andrea Faulds <ajf@ajf.me> Date: Fri Mar 25 16:59:20 2016 +0000 UPGRADING and NEWS commit dca9d4a36c845bfe4fbcb9db18e184469110ea5a Author: Andrea Faulds <ajf@ajf.me> Date: Fri Mar 25 16:45:18 2016 +0000 Add tests contributed by @jesseschalken commit e557f77eab692ed8bb18dbdff48777d80b6f6cbd Author: Andrea Faulds <ajf@ajf.me> Date: Fri Mar 25 16:44:51 2016 +0000 Rebuild VM commit 70942e4c3cbb6b4fe6305b27e1e1b2bed78e76df Author: Andrea Faulds <ajf@ajf.me> Date: Wed Feb 24 13:12:26 2016 +0000 Add test for evaluation order of nested list() keys commit ed3592e80c5231d9e9a95558aa768a42b75bdebc Author: Andrea Faulds <ajf@ajf.me> Date: Wed Feb 24 12:42:04 2016 +0000 Add test for evaluation order commit 589756cbcccbb4702c90b5aa9c091af446058ca1 Author: Andrea Faulds <ajf@ajf.me> Date: Tue Jan 19 17:29:34 2016 +0000 Allow arbitrary expressions for key commit 3f622077c32fcd82fcf27a41bd0f22e2552ec4c5 Author: Andrea Faulds <ajf@ajf.me> Date: Tue Jan 19 17:45:10 2016 +0000 Remove compile-time HANDLE_NUMERIC (see bug #63217) commit bab758119aec63289a2c5bef6a5f90a7bc6441a2 Author: Andrea Faulds <ajf@ajf.me> Date: Sun Jan 17 01:20:26 2016 +0000 Handle numeric strings commit 14bfe93ddc34d1175bccb42a158be8842c472a9c Author: Andrea Faulds <ajf@ajf.me> Date: Sun Jan 17 01:09:36 2016 +0000 Allow trailing comma commit f4c8b2cb30fc074b15b5f7aabef5444382403b5d Author: Andrea Faulds <ajf@ajf.me> Date: Sat Jan 16 23:47:11 2016 +0000 Add tests commit 0085884a6176c3a981b53131fbb4fa0c44db2670 Author: Andrea Faulds <ajf@ajf.me> Date: Sat Jan 16 22:24:23 2016 +0000 Handle non-integer/string opcodes commit e572d2d0ada6a64b36a2c6f5e8cb57439f51b55e Author: Andrea Faulds <ajf@ajf.me> Date: Sat Jan 16 21:10:33 2016 +0000 Disallow mixing keyed and unkeyed list() elements commit cede13ccfe0c486591fa84764271ac1b8cb90d0b Author: Andrea Faulds <ajf@ajf.me> Date: Sun Jan 10 20:46:44 2016 +0000 list() with keys (no foreach or tests)
2016-03-26 01:18:42 +08:00
--TEST--
list() with keys
--FILE--
<?php
$antonyms = [
"good" => "bad",
"happy" => "sad",
];
list("good" => $good_antonym, "happy" => $happy_antonym) = $antonyms;
var_dump($good_antonym, $happy_antonym);
echo PHP_EOL;
$powersOfTwo = [
1 => 2,
2 => 4,
3 => 8
];
list(1 => $two_1, 2 => $two_2, 3 => $two_3) = $powersOfTwo;
var_dump($two_1, $two_2, $two_3);
echo PHP_EOL;
$contrivedMixedKeyTypesExample = [
7 => "the best PHP version",
"elePHPant" => "the cutest mascot"
];
list(7 => $seven, "elePHPant" => $elePHPant) = $contrivedMixedKeyTypesExample;
var_dump($seven, $elePHPant);
echo PHP_EOL;
$allTogetherNow = [
"antonyms" => $antonyms,
"powersOfTwo" => $powersOfTwo,
"contrivedMixedKeyTypesExample" => $contrivedMixedKeyTypesExample
];
list(
"antonyms" => list("good" => $good_antonym, "happy" => $happy_antonym),
"powersOfTwo" => list(1 => $two_1, 2 => $two_2, 3 => $two_3),
"contrivedMixedKeyTypesExample" => list(7 => $seven, "elePHPant" => $elePHPant)
) = $allTogetherNow;
var_dump($good_antonym, $happy_antonym);
var_dump($two_1, $two_2, $two_3);
var_dump($seven, $elePHPant);
?>
--EXPECT--
string(3) "bad"
string(3) "sad"
int(2)
int(4)
int(8)
string(20) "the best PHP version"
string(17) "the cutest mascot"
string(3) "bad"
string(3) "sad"
int(2)
int(4)
int(8)
string(20) "the best PHP version"
string(17) "the cutest mascot"