From php docs
I found this but confused totally what are the difference between these operators (= and =&)
$instance = new SimpleClass();
$assigned = $instance;
$reference =& $instance;
Can anyone explain about this properly, please?
From php docs
I found this but confused totally what are the difference between these operators (= and =&)
$instance = new SimpleClass();
$assigned = $instance;
$reference =& $instance;
Can anyone explain about this properly, please?
<?php
$a = 1;
$b = $a;
$b = 2;
echo "a:{$a} / b: {$b}<br />";
// returns 1/2
$a = 1;
$b =& $a;
$b = 2;
echo "a:{$a} / b: {$b}<br />";
// returns 2/2
?>
Above example clarifies the difference
You may understood as following:
$instance = "5";
$assigned = $instance; // stores "5"
$reference =& $instance; // Point to the object $instance stores "5"
$instance = null; // $instance and $reference become null
Which means
$instance has the value "5" would be null
$assigned has the value "5" wouldn't be null coz it is stored with "5"
$reference has the value "5" would be null as it is pointed to $instance