Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace/qualify call_user_func_array. #1083

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1074.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix PHP backtraces by qualifying/replacing `call_user_func_array` calls [#1074](https://github.com/smarty-php/smarty/issues/1074)
2 changes: 1 addition & 1 deletion src/BlockHandler/BlockPluginWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function __construct($callback, bool $cacheable = true) {
}

public function handle($params, $content, Template $template, &$repeat) {
return call_user_func_array($this->callback, [$params, $content, &$template, &$repeat]);
return \call_user_func_array($this->callback, [$params, $content, &$template, &$repeat]);
}
}
9 changes: 5 additions & 4 deletions src/Compiler/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public function getPluginFromDefaultHandler($tag, $plugin_type) {
$script = null;
$cacheable = true;

$result = call_user_func_array(
$result = \call_user_func_array(
$defaultPluginHandlerFunc,
[
$tag,
Expand Down Expand Up @@ -1281,9 +1281,10 @@ protected function doCompile($_content, $isTemplateSource = false) {
}
// call post compile callbacks
foreach ($this->postCompileCallbacks as $cb) {
$parameter = $cb;
$parameter[0] = $this;
call_user_func_array($cb[0], $parameter);
$callbackFunction = $cb[0];
$parameters = $cb;
$parameters[0] = $this;
$callbackFunction(...$parameters);
}
// return compiled code
return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode;
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/CallbackWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(string $modifierName, $callback) {

public function handle(...$params) {
try {
return call_user_func_array($this->callback, $params);
return ($this->callback)(...$params);
} catch (\ArgumentCountError $e) {
throw new Exception("Invalid number of arguments to modifier " . $this->modifierName);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Runtime/DefaultPluginHandlerRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function hasPlugin($tag, $plugin_type): bool {
$script = null;
$cacheable = null;

return (call_user_func_array(
return (\call_user_func_array(
$this->defaultPluginHandler,
[
$tag,
Expand Down Expand Up @@ -54,7 +54,7 @@ public function getCallback($tag, $plugin_type) {
$script = null;
$cacheable = null;

if (call_user_func_array(
if (\call_user_func_array(
$this->defaultPluginHandler,
[
$tag,
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function getContent() {
*/
public function _getDefaultTemplate($default_handler) {
$_content = $_timestamp = null;
$_return = call_user_func_array(
$_return = \call_user_func_array(
$default_handler,
[$this->type, $this->name, &$_content, &$_timestamp, $this->smarty]
);
Expand Down