Skip to content

Instantly share code, notes, and snippets.

@woduda
Created February 13, 2018 15:38
Show Gist options
  • Save woduda/05c5b9c3a992f892820b8dad006e5a81 to your computer and use it in GitHub Desktop.
Save woduda/05c5b9c3a992f892820b8dad006e5a81 to your computer and use it in GitHub Desktop.
Test how passing object by reference works in PHP
<?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