Created
February 13, 2018 15:38
-
-
Save woduda/05c5b9c3a992f892820b8dad006e5a81 to your computer and use it in GitHub Desktop.
Test how passing object by reference works in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A | |
{ | |
private $id = 0; | |
public function __construct($id) | |
{ | |
$this->id = $id; | |
} | |
public function setId($id) | |
{ | |
$this->id = $id; | |
} | |
} | |
function x(A &$a) | |
{ | |
$b = new A(3); | |
$a = $b; | |
//$a->setId(5); | |
} | |
$a = new A(1); | |
print_r($a); | |
x($a); | |
print_r($a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment