Skip to content

Instantly share code, notes, and snippets.

@mmoreram
Last active May 25, 2022 10:02
Show Gist options
  • Save mmoreram/d0965b4994a69f134036b265a260ec9a to your computer and use it in GitHub Desktop.
Save mmoreram/d0965b4994a69f134036b265a260ec9a to your computer and use it in GitHub Desktop.
<?php
class X {
private int $a = 0;
public function incr() {
$this->a++;
}
public function a() {
return $this->a;
}
}
class A {
private readonly X $x;
public function __construct(X $x) {
$this->x = $x;
}
public function b() {
$this->x->incr();
return $this->x->a();
}
}
$a = new A(new X());
var_dump($a->b());
@mmoreram
Copy link
Author

The result is 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment