Skip to content

Instantly share code, notes, and snippets.

@pgilad
Created October 24, 2018 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgilad/00e82aeff2630b42e76f28018d8cee4f to your computer and use it in GitHub Desktop.
Save pgilad/00e82aeff2630b42e76f28018d8cee4f to your computer and use it in GitHub Desktop.
Php instance property mutation
<?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