0

PHP documentation states:

Since PHP 5, new returns a reference automatically

Any examples to illustrate this statement?

Robert
  • 10,126
  • 19
  • 78
  • 130

2 Answers2

1

Here is an example:

class reftest
{
    public $a = 1;
}

$reference = new reftest();
$reference2 = $reference;
$reference->a = 2;

echo $reference->a;  // echoes 2.
echo $reference2->a; // echoes 2.

Note that both $reference and $reference2 have the value of the member $a equal to 2, despite the value was only assigned to the $reference.

Sergiy Belozorov
  • 5,856
  • 7
  • 40
  • 73
0
<?php
$a = new ClassA();
$b = $a;

Variables $a and $b are pointing to the same place, where ClassA resource exists.

Alexandru Guzinschi
  • 5,675
  • 1
  • 29
  • 40