Created
October 24, 2018 07:54
-
-
Save pgilad/00e82aeff2630b42e76f28018d8cee4f to your computer and use it in GitHub Desktop.
Php instance property mutation
This file contains hidden or 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 State { | |
public $foo = 0; | |
} | |
class Mutator { | |
public function mutateState(State $state) { | |
$state->foo = 4; | |
} | |
} | |
$state = new State(); | |
echo $state->foo . "\n"; | |
$state->foo = 2; | |
echo $state->foo . "\n"; | |
$mutator = new Mutator(); | |
$mutator->mutateState($state); | |
echo $state->foo . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment