Skip to content

Instantly share code, notes, and snippets.

@broskees
Last active June 13, 2023 15:58
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 broskees/0f638ebbeea65c8d399b86a355ea5dc0 to your computer and use it in GitHub Desktop.
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)
<?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