1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
--TEST--
Evaluation order during assignments.
--FILE--
<?php
function f() {
echo "in f()\n";
return "name";
}
function g() {
echo "in g()\n";
return "assigned value";
}
echo "\n\nOrder with local assignment:\n";
${f()} = g();
var_dump($name);
echo "\n\nOrder with array assignment:\n";
$a[f()] = g();
var_dump($a);
echo "\n\nOrder with object property assignment:\n";
$oa = new stdClass;
$oa->${f()} = g();
var_dump($oa);
echo "\n\nOrder with nested object property assignment:\n";
$ob = new stdClass;
$ob->o1 = new stdClass;
$ob->o1->o2 = new stdClass;
$ob->o1->o2->${f()} = g();
var_dump($ob);
echo "\n\nOrder with dim_list property assignment:\n";
$oc = new stdClass;
$oc->a[${f()}] = g();
var_dump($oc);
class C {
public static $name = "original";
public static $a = array();
public static $string = "hello";
}
echo "\n\nOrder with static property assignment:\n";
C::${f()} = g();
var_dump(C::$name);
echo "\n\nOrder with static array property assignment:\n";
C::$a[f()] = g();
var_dump(C::$a);
echo "\n\nOrder with indexed string assignment:\n";
$string = "hello";
function getOffset() {
echo "in getOffset()\n";
return 0;
}
function newChar() {
echo "in newChar()\n";
return 'j';
}
$string[getOffset()] = newChar();
var_dump($string);
echo "\n\nOrder with static string property assignment:\n";
C::$string[getOffset()] = newChar();
var_dump(C::$string);
?>
--EXPECTF--
Order with local assignment:
in f()
in g()
%string|unicode%(14) "assigned value"
Order with array assignment:
in f()
in g()
array(1) {
[%u|b%"name"]=>
%string|unicode%(14) "assigned value"
}
Order with object property assignment:
in f()
in g()
object(stdClass)#%d (1) {
[%u|b%"assigned value"]=>
%string|unicode%(14) "assigned value"
}
Order with nested object property assignment:
in f()
in g()
object(stdClass)#%d (1) {
[%u|b%"o1"]=>
object(stdClass)#%d (1) {
[%u|b%"o2"]=>
object(stdClass)#%d (1) {
[%u|b%"assigned value"]=>
%string|unicode%(14) "assigned value"
}
}
}
Order with dim_list property assignment:
in f()
in g()
object(stdClass)#%d (1) {
[%u|b%"a"]=>
array(1) {
[%u|b%"assigned value"]=>
%string|unicode%(14) "assigned value"
}
}
Order with static property assignment:
in f()
in g()
%string|unicode%(14) "assigned value"
Order with static array property assignment:
in f()
in g()
array(1) {
[%u|b%"name"]=>
%string|unicode%(14) "assigned value"
}
Order with indexed string assignment:
in getOffset()
in newChar()
%string|unicode%(5) "jello"
Order with static string property assignment:
in getOffset()
in newChar()
%string|unicode%(5) "jello"
|