File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / lang / engine_assignExecutionOrder_002.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 6 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>