Last active
June 13, 2023 15:58
-
-
Save broskees/0f638ebbeea65c8d399b86a355ea5dc0 to your computer and use it in GitHub Desktop.
A function for getting a private property from an object — for use in Roots Acorn & Laravel (SHOULD BE USED FOR DEBUGGING ONLY)
This file contains 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 | |
/** | |
* Get a private property from an object. | |
* | |
* @param object $that | |
* @param string $var | |
* @return mixed | |
*/ | |
function &getPrivateProp(&$that, $var): mixed | |
{ | |
return \Closure::bind(fn &($that) => $that->$var, $that, $that)($that); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment