File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / lang / passByReference_006.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, 4 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: Pass uninitialised objects and arrays by reference to test implicit initialisation.
    3: --FILE--
    4: <?php
    5: 
    6: function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) {
    7:   $ref1 = "Ref1 changed";
    8:   $ref2 = "Ref2 changed";
    9:   $ref3 = "Ref3 changed";
   10:   $ref4 = "Ref4 changed";
   11:   $ref5 = "Ref5 changed";
   12: }
   13: 
   14: 
   15: class C {
   16: 
   17: 	function __construct(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) {
   18: 	  $ref1 = "Ref1 changed";
   19: 	  $ref2 = "Ref2 changed";
   20: 	  $ref3 = "Ref3 changed";
   21: 	  $ref4 = "Ref4 changed";
   22: 	  $ref5 = "Ref5 changed";
   23: 	}
   24: 
   25: 	function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) {
   26: 	  $ref1 = "Ref1 changed";
   27: 	  $ref2 = "Ref2 changed";
   28: 	  $ref3 = "Ref3 changed";
   29: 	  $ref4 = "Ref4 changed";
   30: 	  $ref5 = "Ref5 changed";
   31: 	}
   32: 
   33: } 
   34: 
   35: echo "\n ---- Pass uninitialised array & object by ref: function call ---\n";
   36: unset($u1, $u2, $u3, $u4, $u5);
   37: refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
   38: var_dump($u1, $u2, $u3, $u4, $u5);
   39: 
   40: echo "\n ---- Pass uninitialised arrays & objects by ref: static method call ---\n";
   41: unset($u1, $u2, $u3, $u4, $u5);
   42: C::refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
   43: var_dump($u1, $u2, $u3, $u4, $u5);
   44: 
   45: echo "\n\n---- Pass uninitialised arrays & objects by ref: constructor ---\n";
   46: unset($u1, $u2, $u3, $u4, $u5);
   47: $c = new C($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
   48: var_dump($u1, $u2, $u3, $u4, $u5);
   49: 
   50: echo "\n ---- Pass uninitialised arrays & objects by ref: instance method call ---\n";
   51: unset($u1, $u2, $u3, $u4, $u5);
   52: $c->refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
   53: var_dump($u1, $u2, $u3, $u4, $u5);
   54: 
   55: ?>
   56: --EXPECTF--
   57: 
   58:  ---- Pass uninitialised array & object by ref: function call ---
   59: array(1) {
   60:   [0]=>
   61:   string(12) "Ref1 changed"
   62: }
   63: array(1) {
   64:   [0]=>
   65:   array(1) {
   66:     [1]=>
   67:     string(12) "Ref2 changed"
   68:   }
   69: }
   70: object(stdClass)#%d (1) {
   71:   ["a"]=>
   72:   string(12) "Ref3 changed"
   73: }
   74: object(stdClass)#%d (1) {
   75:   ["a"]=>
   76:   object(stdClass)#%d (1) {
   77:     ["b"]=>
   78:     string(12) "Ref4 changed"
   79:   }
   80: }
   81: object(stdClass)#%d (1) {
   82:   ["a"]=>
   83:   object(stdClass)#%d (1) {
   84:     ["b"]=>
   85:     object(stdClass)#%d (1) {
   86:       ["c"]=>
   87:       string(12) "Ref5 changed"
   88:     }
   89:   }
   90: }
   91: 
   92:  ---- Pass uninitialised arrays & objects by ref: static method call ---
   93: 
   94: Strict Standards: Non-static method C::refs() should not be called statically in %s on line 39
   95: array(1) {
   96:   [0]=>
   97:   string(12) "Ref1 changed"
   98: }
   99: array(1) {
  100:   [0]=>
  101:   array(1) {
  102:     [1]=>
  103:     string(12) "Ref2 changed"
  104:   }
  105: }
  106: object(stdClass)#%d (1) {
  107:   ["a"]=>
  108:   string(12) "Ref3 changed"
  109: }
  110: object(stdClass)#%d (1) {
  111:   ["a"]=>
  112:   object(stdClass)#%d (1) {
  113:     ["b"]=>
  114:     string(12) "Ref4 changed"
  115:   }
  116: }
  117: object(stdClass)#%d (1) {
  118:   ["a"]=>
  119:   object(stdClass)#%d (1) {
  120:     ["b"]=>
  121:     object(stdClass)#%d (1) {
  122:       ["c"]=>
  123:       string(12) "Ref5 changed"
  124:     }
  125:   }
  126: }
  127: 
  128: 
  129: ---- Pass uninitialised arrays & objects by ref: constructor ---
  130: array(1) {
  131:   [0]=>
  132:   string(12) "Ref1 changed"
  133: }
  134: array(1) {
  135:   [0]=>
  136:   array(1) {
  137:     [1]=>
  138:     string(12) "Ref2 changed"
  139:   }
  140: }
  141: object(stdClass)#%d (1) {
  142:   ["a"]=>
  143:   string(12) "Ref3 changed"
  144: }
  145: object(stdClass)#%d (1) {
  146:   ["a"]=>
  147:   object(stdClass)#%d (1) {
  148:     ["b"]=>
  149:     string(12) "Ref4 changed"
  150:   }
  151: }
  152: object(stdClass)#%d (1) {
  153:   ["a"]=>
  154:   object(stdClass)#%d (1) {
  155:     ["b"]=>
  156:     object(stdClass)#%d (1) {
  157:       ["c"]=>
  158:       string(12) "Ref5 changed"
  159:     }
  160:   }
  161: }
  162: 
  163:  ---- Pass uninitialised arrays & objects by ref: instance method call ---
  164: array(1) {
  165:   [0]=>
  166:   string(12) "Ref1 changed"
  167: }
  168: array(1) {
  169:   [0]=>
  170:   array(1) {
  171:     [1]=>
  172:     string(12) "Ref2 changed"
  173:   }
  174: }
  175: object(stdClass)#%d (1) {
  176:   ["a"]=>
  177:   string(12) "Ref3 changed"
  178: }
  179: object(stdClass)#%d (1) {
  180:   ["a"]=>
  181:   object(stdClass)#%d (1) {
  182:     ["b"]=>
  183:     string(12) "Ref4 changed"
  184:   }
  185: }
  186: object(stdClass)#%d (1) {
  187:   ["a"]=>
  188:   object(stdClass)#%d (1) {
  189:     ["b"]=>
  190:     object(stdClass)#%d (1) {
  191:       ["c"]=>
  192:       string(12) "Ref5 changed"
  193:     }
  194:   }
  195: }

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