Skip to content

Instantly share code, notes, and snippets.

@sanmai
Created September 9, 2014 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanmai/a4a5d2f374eef519c7c1 to your computer and use it in GitHub Desktop.
Save sanmai/a4a5d2f374eef519c7c1 to your computer and use it in GitHub Desktop.
Use keyword and objects in PHP
<?php
class A {
public $test = 1;
}
$a = new A();
$func = function () use ($a) {
$a->test += 1;
};
$func();
var_dump($a->test == 1); // false
var_dump($a->test == 2); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment