list_keyed_ArrayAccess.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. list() with keys and ArrayAccess
  3. --FILE--
  4. <?php
  5. $antonymObject = new ArrayObject;
  6. $antonymObject["good"] = "bad";
  7. $antonymObject["happy"] = "sad";
  8. list("good" => $good, "happy" => $happy) = $antonymObject;
  9. var_dump($good, $happy);
  10. echo PHP_EOL;
  11. $stdClassCollection = new SplObjectStorage;
  12. $foo = new StdClass;
  13. $stdClassCollection[$foo] = "foo";
  14. $bar = new StdClass;
  15. $stdClassCollection[$bar] = "bar";
  16. list($foo => $fooStr, $bar => $barStr) = $stdClassCollection;
  17. var_dump($fooStr, $barStr);
  18. echo PHP_EOL;
  19. class IndexPrinter implements ArrayAccess
  20. {
  21. public function offsetGet($offset) {
  22. echo "GET ";
  23. var_dump($offset);
  24. }
  25. public function offsetSet($offset, $value) {
  26. }
  27. public function offsetExists($offset) {
  28. }
  29. public function offsetUnset($offset) {
  30. }
  31. }
  32. $op = new IndexPrinter;
  33. list(123 => $x) = $op;
  34. // PHP shouldn't convert this to an integer offset, because it's ArrayAccess
  35. list("123" => $x) = $op;
  36. ?>
  37. --EXPECT--
  38. string(3) "bad"
  39. string(3) "sad"
  40. string(3) "foo"
  41. string(3) "bar"
  42. GET int(123)
  43. GET string(3) "123"