Skip to content

Instantly share code, notes, and snippets.

@lightsuner
Last active August 29, 2015 13:57
Show Gist options
  • Save lightsuner/9364195 to your computer and use it in GitHub Desktop.
Save lightsuner/9364195 to your computer and use it in GitHub Desktop.
Required php 5.4 - Provide access layer to private properties via anonymous functions
<?php
class TestClass
{
private $someVar;
public function __construct()
{
$this->someVar = 10;
}
}
$testObj = new TestClass();
$someVarGetter = function () {
return $this->someVar;
};
$someVarGetter = $someVarGetter->bindTo($testObj, $testObj);
echo $someVarGetter(); // 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment