Permalink
Browse files

Add checks for builtin (user defined) functions to reduce warnings

  • Loading branch information...
steffen
steffen committed May 25, 2015
1 parent 94a2685 commit 7e328723dc4084cf105e59aef5363528e8142c64
Showing with 13 additions and 3 deletions.
  1. +1 −1 Library/Compiler.php
  2. +12 −2 Library/FunctionCall.php
@@ -50,7 +50,7 @@ class Compiler
/**
* @var FunctionDefinition[]
*/
protected $functionDefinitions = array();
public $functionDefinitions = array();
/**
* @var array|string[]
@@ -270,14 +270,24 @@ public function isBuiltInFunction($functionName)
* @param string $functionName
* @return boolean
*/
public function functionExists($functionName)
public function functionExists($functionName, CompilationContext $context)
{
if (function_exists($functionName)) {
return true;
}
if ($this->isBuiltInFunction($functionName)) {
return true;
}
$internalName[] = 'f__'.$functionName;
if (isset($context->classDefinition)) {
$internalName[] = 'f_'.str_replace('\\', '_', strtolower($context->classDefinition->getNamespace())).'_'.$functionName;
}
foreach ($internalName as $name) {
if (isset($context->compiler->functionDefinitions[$name])) {
return true;
}
}
return false;
}
@@ -302,7 +312,7 @@ protected function _callNormal(array $expression, CompilationContext $compilatio
}
$exists = true;
if (!$this->functionExists($funcName)) {
if (!$this->functionExists($funcName, $compilationContext)) {
$compilationContext->logger->warning("Function \"$funcName\" does not exist at compile time", "nonexistent-function", $expression);
$exists = false;
}

0 comments on commit 7e32872

Please sign in to comment.