Open j-applese3d opened 1 month ago
Sounds good. Just to be sure: you are saying it would be better to add a backslash before each time Smarty uses call_user_func_array
from a namespaced file?
Yes, that is correct.
Either that (add \
in front of every call_user_func_array
),
Or add use function call_user_func_array;
Or don't use call_user_func_array at all and simply execute the callable: ($this->callback)(...$params);
But again, it's not a "smarty problem" so if you do not wish to add \
everywhere, I can also understand and do not mind. :slightly_smiling_face:
This feels like a PHP bug, so feel free to close as off-topic/won't fix. :smiley:
Basically, the stack trace - as returned from
debug_backtrace()
- is messed up when callingcall_user_func_array()
from within a namespace.Simple PHP example:
The output is:
But, if you Fully-Qualify the function used, then you'll find the trace is "normal". You can qualify the function by either prepending a
\
like\call_user_func_array(...
, or you can add ause function call_user_func_array;
statement at the topEither method will fix the trace, and will have the added [alleged] benefit of being faster (as it doesn't have to check for a namespaced function):
How does this affect Smarty?
Smarty makes use of
call_user_func_array
. Ex: in Extension\CallbackWrapper.php. https://github.com/smarty-php/smarty/blob/a1b4c9c551d01ff63220f053966c7aaa9053f89d/src/Extension/CallbackWrapper.php#L29This could be changed to either Fully Qualify the function (as explained above), or call_user_func_array could simply be dropped and use the splat operator like so:
But like I mentioned, the entire issue is somewhat beyond the scope of Smarty. Just figured it may be of some interest.