mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
Throw deprecation notice about unregistered functions without changing the compilation flow (#985)
Fixes #964
This commit is contained in:
@@ -640,17 +640,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
return $func_name . '(' . $parameter[ 0 ] . ')';
|
return $func_name . '(' . $parameter[ 0 ] . ')';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$first_param = array_shift($parameter);
|
|
||||||
$modifier = array_merge(array($name), $parameter);
|
if (
|
||||||
// Now, compile the function call as a modifier
|
!$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
|
||||||
return $this->compileTag(
|
&& !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
|
||||||
'private_modifier',
|
&& !in_array($name, ['time', 'join', 'is_array', 'in_array'])
|
||||||
array(),
|
) {
|
||||||
array(
|
trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
|
||||||
'modifierlist' => array($modifier),
|
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
|
||||||
'value' => $first_param
|
'a custom modifier.', E_USER_DEPRECATED);
|
||||||
)
|
}
|
||||||
);
|
|
||||||
|
return $name . '(' . implode(',', $parameter) . ')';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->trigger_template_error("unknown function '{$name}'");
|
$this->trigger_template_error("unknown function '{$name}'");
|
||||||
|
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ArgumentMustBePassedByReference961Test extends PHPUnit_Smarty
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group issue961
|
||||||
|
*/
|
||||||
|
public function testReset()
|
||||||
|
{
|
||||||
|
$smarty = new Smarty();
|
||||||
|
$smarty->registerPlugin('modifier', 'reset', 'reset');
|
||||||
|
$templateStr = "string:{reset(\$ar)}";
|
||||||
|
$smarty->assign('ar', [1,2,3]);
|
||||||
|
$this->assertEquals(
|
||||||
|
'1',
|
||||||
|
$smarty->fetch($templateStr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group issue961
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function testResetAsModifier()
|
||||||
|
{
|
||||||
|
$smarty = new Smarty();
|
||||||
|
try {
|
||||||
|
$templateStr = "string:{\$ar|reset}";
|
||||||
|
$smarty->assign('ar', [1,2,3]);
|
||||||
|
$this->assertEquals(
|
||||||
|
'1',
|
||||||
|
$smarty->fetch($templateStr)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group issue961
|
||||||
|
*/
|
||||||
|
public function testResetInExpression()
|
||||||
|
{
|
||||||
|
$smarty = new Smarty();
|
||||||
|
$smarty->registerPlugin('modifier', 'reset', 'reset');
|
||||||
|
$templateStr = "string:{if reset(\$ar)}ok{/if}";
|
||||||
|
$smarty->assign('ar', [1,2,3]);
|
||||||
|
$this->assertEquals(
|
||||||
|
'ok',
|
||||||
|
$smarty->fetch($templateStr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group issue961
|
||||||
|
*/
|
||||||
|
public function testMatch()
|
||||||
|
{
|
||||||
|
$smarty = new Smarty();
|
||||||
|
$smarty->registerPlugin('modifier', 'preg_match', 'preg_match');
|
||||||
|
$templateStr = 'string:{assign var="match" value=null}{if preg_match(\'/([a-z]{4})/\', "a test", $match)}{$match.1}{/if}';
|
||||||
|
$this->assertEquals(
|
||||||
|
'test',
|
||||||
|
$smarty->fetch($templateStr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user