mirror of
https://github.com/smarty-php/smarty.git
synced 2025-07-31 16:37:14 +02:00
Throw deprecation notice about unregistered functions without changing the compilation flow.
Fixes #964
This commit is contained in:
@@ -640,17 +640,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
return $func_name . '(' . $parameter[ 0 ] . ')';
|
||||
}
|
||||
} else {
|
||||
$first_param = array_shift($parameter);
|
||||
$modifier = array_merge(array($name), $parameter);
|
||||
// Now, compile the function call as a modifier
|
||||
return $this->compileTag(
|
||||
'private_modifier',
|
||||
array(),
|
||||
array(
|
||||
'modifierlist' => array($modifier),
|
||||
'value' => $first_param
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
|
||||
&& !$this->getPlugin($name, Smarty::PLUGIN_MODIFIER)
|
||||
&& !in_array($name, ['time', 'join', 'is_array', 'in_array'])
|
||||
) {
|
||||
trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
|
||||
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
|
||||
'a custom modifier.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return $name . '(' . implode(',', $parameter) . ')';
|
||||
}
|
||||
} else {
|
||||
$this->trigger_template_error("unknown function '{$name}'");
|
||||
|
@@ -0,0 +1,74 @@
|
||||
<?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();
|
||||
|
||||
// $previousErrorReporting = $smarty->error_reporting;
|
||||
// $smarty->setErrorReporting($previousErrorReporting | E_USER_DEPRECATED);
|
||||
// $smarty->registerPlugin('modifier', 'reset', 'reset');
|
||||
// $this->expectDeprecation();
|
||||
try {
|
||||
$templateStr = "string:{\$ar|reset}";
|
||||
$smarty->assign('ar', [1,2,3]);
|
||||
$this->assertEquals(
|
||||
'1',
|
||||
$smarty->fetch($templateStr)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
// $smarty->setErrorReporting($previousErrorReporting);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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