Annotation of embedaddon/php/tests/classes/new_001.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Confirm difference between assigning new directly and by reference.
! 3: --INI--
! 4: error_reporting=E_ALL | E_DEPRECATED
! 5: --FILE--
! 6: <?php
! 7: echo "Compile-time strict error message should precede this.\n";
! 8:
! 9: class Inc
! 10: {
! 11: private static $counter = 0;
! 12: function __construct()
! 13: {
! 14: $this->id = ++Inc::$counter;
! 15: }
! 16: }
! 17:
! 18: $f = new Inc();
! 19: $k =& $f;
! 20: echo "\$f initially points to the first object:\n";
! 21: var_dump($f);
! 22:
! 23: echo "Assigning new object directly to \$k affects \$f:\n";
! 24: $k = new Inc();
! 25: var_dump($f);
! 26:
! 27: echo "Assigning new object by ref to \$k removes it from \$f's reference set, so \$f is unchanged:\n";
! 28: $k =& new Inc();
! 29: var_dump($f);
! 30: ?>
! 31: --EXPECTF--
! 32: Deprecated: Assigning the return value of new by reference is deprecated in %s on line 23
! 33: Compile-time strict error message should precede this.
! 34: $f initially points to the first object:
! 35: object(Inc)#%d (1) {
! 36: ["id"]=>
! 37: int(1)
! 38: }
! 39: Assigning new object directly to $k affects $f:
! 40: object(Inc)#%d (1) {
! 41: ["id"]=>
! 42: int(2)
! 43: }
! 44: Assigning new object by ref to $k removes it from $f's reference set, so $f is unchanged:
! 45: object(Inc)#%d (1) {
! 46: ["id"]=>
! 47: int(2)
! 48: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>