Skip to content

Instantly share code, notes, and snippets.

@ilhamarrouf
Created February 28, 2017 17:47
Show Gist options
  • Save ilhamarrouf/793c46ebf5db914a1e058c20f48e9fac to your computer and use it in GitHub Desktop.
Save ilhamarrouf/793c46ebf5db914a1e058c20f48e9fac to your computer and use it in GitHub Desktop.
OOP PHP
<?php
class A
{
public $foo = 1;
}
$a = new A;
$b = $a; // $a and $b are copies of the same identifier
// ($a) = ($b) = <id>
$b->foo = 2;
echo $a->foo."\n";
$c = new A;
$d = &$c; // $c and $d are references
// ($c,$d) = <id>
$d->foo = 2;
echo $c->foo."\n";
?>
// Result
2
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment