|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHPSA\Compiler\Expression; |
|
4
|
|
|
|
|
5
|
|
|
use PHPSA\CompiledExpression; |
|
6
|
|
|
use PHPSA\Context; |
|
7
|
|
|
use PHPSA\Compiler\Expression; |
|
8
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
|
9
|
|
|
use PHPSA\Definition\ClassDefinition; |
|
10
|
|
|
|
|
11
|
|
|
class ClassConstFetch extends AbstractExpressionCompiler |
|
12
|
|
|
{ |
|
13
|
|
|
protected $name = 'PhpParser\Node\Expr\ClassConstFetch'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* classname::class, classname::CONSTANTNAME, ... |
|
17
|
|
|
* |
|
18
|
|
|
* @param \PhpParser\Node\Expr\ClassConstFetch $expr |
|
19
|
|
|
* @param Context $context |
|
20
|
|
|
* @return CompiledExpression |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function compile($expr, Context $context) |
|
23
|
|
|
{ |
|
24
|
|
|
$compiler = $context->getExpressionCompiler(); |
|
25
|
|
|
|
|
26
|
|
|
if ($expr->name == 'class') { |
|
27
|
|
|
// @todo return fully qualified classname |
|
28
|
|
|
return new CompiledExpression(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$leftCE = $compiler->compile($expr->class); |
|
32
|
|
|
if ($leftCE->isObject()) { |
|
33
|
|
|
$leftCEValue = $leftCE->getValue(); |
|
34
|
|
|
if ($leftCEValue instanceof ClassDefinition) { |
|
35
|
|
|
if (!$leftCEValue->hasConst($expr->name, true)) { |
|
|
|
|
|
|
36
|
|
|
$context->notice( |
|
37
|
|
|
'language_error', |
|
38
|
|
|
sprintf('Constant %s does not exist in %s scope', $expr->name, $expr->class), |
|
39
|
|
|
$expr |
|
40
|
|
|
); |
|
41
|
|
|
return new CompiledExpression(CompiledExpression::UNKNOWN); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return new CompiledExpression(); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$context->debug('Unknown const fetch', $expr); |
|
49
|
|
|
return new CompiledExpression(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: