Skip to content

Commit

Permalink
PhpWriter: added warning about deprecated variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 30, 2016
1 parent 814a9db commit d3f86a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Latte/PhpWriter.php
Expand Up @@ -174,12 +174,16 @@ public function preprocess(MacroTokens $tokens = NULL)
*/
public function validateTokens(MacroTokens $tokens)
{
$deprecatedVars = array_flip(['$template', '$_b', '$_l', '$_g', '$_args', '$_fi', '$_control', '$_presenter', '$_form', '$_input', '$_label', '$_snippetMode']);
$brackets = [];
$pos = $tokens->position;
while ($tokens->nextToken()) {
if ($tokens->isCurrent('?>')) {
throw new CompileException('Forbidden ?> inside macro');

} elseif ($tokens->isCurrent($tokens::T_VARIABLE) && isset($deprecatedVars[$tokens->currentValue()])) {
trigger_error("Variable {$tokens->currentValue()} is deprecated.", E_USER_DEPRECATED);

} elseif ($tokens->isCurrent($tokens::T_SYMBOL)
&& !$tokens->isPrev('::') && !$tokens->isPrev('->')
&& preg_match('#^[A-Z0-9]{3,}$#', $val = $tokens->currentValue())
Expand Down
4 changes: 4 additions & 0 deletions tests/Latte/Compiler.errors.phpt
Expand Up @@ -94,3 +94,7 @@ Assert::exception(function () use ($latte) {
Assert::noError(function () use ($latte) {
$latte->compile('{php function () { yield; }}');
});

Assert::error(function () use ($latte) {
$latte->compile('{$_form[$name]}');
}, E_USER_DEPRECATED, 'Variable $_form is deprecated.');

0 comments on commit d3f86a5

Please sign in to comment.