php - Get string representation of anonymous function -
let's have anonymous php function this:
<?php $l = function() { echo "hello world"; }; is possible string representation of anonymous function $l, i.e. string containing function body?
i tried few things:
echo $l;php catchable fatal error: object of class closure not converted stringvar_dump($l);class closure#1 (0) { }echo $l->__tostring();: call undefined method closure::__tostring()get_class_methods($l)returnsarray('bind', 'bindto'), seems no undocumented methods exist$r = new reflectionclass($l);: getproperties(), getconstants() , getstaticproperties() empty,$r->__tostring()not return useful.
i don't need in code, thought might useful logging purposes if goes wrong. after couldn't come solution myself curious if possible @ all.
your "real" option use actual php parser parse anonymous function.
don't fall in the same trap @argon did thinking simple substr_count based script can parse php code. it's brittle , break simple examples in glorious ways.
point in case:
$dog2 = ['bark'=>function($foo = '{'){}]; fatal error: uncaught exception: complex context definition in
Comments
Post a Comment