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