engine_assignExecutionOrder_002.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --TEST--
  2. Evaluation order during assignments.
  3. --FILE--
  4. <?php
  5. // simple case with missing element
  6. $f = array("hello","item2","bye");
  7. list($a,,$b) = $f;
  8. echo "A=$a B=$b\n";
  9. // Warning: Cannot use a scalar value as an array in %s on line %d
  10. $c[$c=1] = 1;
  11. // i++ evaluated first, so $d[0] is 10
  12. $d = array(0,10);
  13. $i = 0;
  14. $d[$i++] = $i*10;
  15. // expected array is 10,10
  16. var_dump($d);
  17. // the f++++ makes f into 2, so $e 0 and 1 should both be 30
  18. $e = array(0,0);
  19. $f = 0;
  20. $g1 = array(10,10);
  21. $g2 = array(20,20);
  22. $g3 = array(30,30);
  23. $g = array($g1,$g2,$g3);
  24. list($e[$f++],$e[$f++]) = $g[2];
  25. // expect 30,30
  26. var_dump($e);
  27. $i1 = array(1,2);
  28. $i2 = array(10,20);
  29. $i3 = array(100,200);
  30. $i4 = array(array(1000,2000),3000);
  31. $i = array($i1,$i2,$i3,$i4);
  32. $j = array(0,0,0);
  33. $h = 0;
  34. // a list of lists
  35. list(list($j[$h++],$j[$h++]),$j[$h++]) = $i[3];
  36. var_dump($j);
  37. // list of lists with just variable assignments - expect 100,200,300
  38. $k3 = array(100,200);
  39. $k = array($k3,300);
  40. list(list($l,$m),$n) = $k;
  41. echo "L=$l M=$m N=$n\n";
  42. // expect $x and $y to be null - this fails on php.net 5.2.1 (invalid opcode) - fixed in 5.2.3
  43. list($o,$p) = 20;
  44. echo "O=$o and P=$p\n";
  45. // list of lists with blanks and nulls expect 10 20 40 50 60 70 80
  46. $q1 = array(10,20,30,40);
  47. $q2 = array(50,60);
  48. $q3 = array($q1,$q2,null,70);
  49. $q4 = array($q3,null,80);
  50. list(list(list($r,$s,,$t),list($u,$v),,$w),,$x) = $q4;
  51. echo "$r $s $t $u $v $w $x\n";
  52. // expect y and z to be undefined
  53. list($y,$z) = array();
  54. echo "Y=$y,Z=$z\n";
  55. // expect h to be defined and be 10
  56. list($aa,$bb) = array(10);
  57. echo "AA=$aa\n";
  58. // expect cc and dd to be 10 and 30
  59. list($cc,,$dd) = array(10,20,30,40);
  60. echo "CC=$cc DD=$dd\n";
  61. // expect the inner array to be defined
  62. $ee = array("original array");
  63. function f() {
  64. global $ee;
  65. $ee = array("array created in f()");
  66. return 1;
  67. }
  68. $ee["array entry created after f()"][f()] = "hello";
  69. print_r($ee);
  70. ?>
  71. --EXPECTF--
  72. A=hello B=bye
  73. Warning: Cannot use a scalar value as an array in %s on line %d
  74. array(2) {
  75. [0]=>
  76. int(10)
  77. [1]=>
  78. int(10)
  79. }
  80. array(2) {
  81. [0]=>
  82. int(30)
  83. [1]=>
  84. int(30)
  85. }
  86. array(3) {
  87. [0]=>
  88. int(1000)
  89. [1]=>
  90. int(2000)
  91. [2]=>
  92. int(3000)
  93. }
  94. L=100 M=200 N=300
  95. O= and P=
  96. 10 20 40 50 60 70 80
  97. Notice: Undefined offset: 0 in %s on line %d
  98. Notice: Undefined offset: 1 in %s on line %d
  99. Y=,Z=
  100. Notice: Undefined offset: 1 in %s on line %d
  101. AA=10
  102. CC=10 DD=30
  103. Array
  104. (
  105. [0] => array created in f()
  106. [array entry created after f()] => Array
  107. (
  108. [1] => hello
  109. )
  110. )