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