Skip to content

gen_stub: Using $this when not in object context #18108

Closed
@DanielEScherzer

Description

@DanielEScherzer

Description

In ext/zend_test/test.stub.php I added

    /** @var string */
    const TEMP_TEST = __FILE__;

and then ran
php build/gen_stub.php ext/zend_test/test.stub.php

Output:

root@228aa53d048d:/usr/src/php# php build/gen_stub.php ext/zend_test/test.stub.php

Fatal error: Uncaught Error: Using $this when not in object context in /usr/src/php/build/gen_stub.php:2173
Stack trace:
#0 /usr/src/php/build/PHP-Parser-5.3.1/lib/PhpParser/ConstExprEvaluator.php(148): EvaluatedValue::{closure}(Object(PhpParser\Node\Scalar\MagicConst\File))
#1 /usr/src/php/build/PHP-Parser-5.3.1/lib/PhpParser/ConstExprEvaluator.php(102): PhpParser\ConstExprEvaluator->evaluate(Object(PhpParser\Node\Scalar\MagicConst\File))
#2 /usr/src/php/build/gen_stub.php(2209): PhpParser\ConstExprEvaluator->evaluateDirectly(Object(PhpParser\Node\Scalar\MagicConst\File))
#3 /usr/src/php/build/gen_stub.php(2615): EvaluatedValue::createFromExpression(Object(PhpParser\Node\Scalar\MagicConst\File), Object(SimpleType), NULL, Array)
#4 /usr/src/php/build/gen_stub.php(5204): ConstInfo->getDeclaration(Array)
#5 /usr/src/php/build/gen_stub.php(125): generateArgInfoCode('test', Object(FileInfo), Array, 'e496fa1faa84677...')
#6 /usr/src/php/build/gen_stub.php(6127): processStubFile('ext/zend_test/t...', Object(Context))
#7 {main}
  thrown in /usr/src/php/build/gen_stub.php on line 2173

Cause:

php-src/build/gen_stub.php

Lines 2119 to 2125 in 6329248

/**
* @param array<string, ConstInfo> $allConstInfos
*/
public static function createFromExpression(Expr $expr, ?SimpleType $constType, ?string $cConstName, array $allConstInfos): EvaluatedValue
{
// This visitor replaces the PHP constants by C constants. It allows direct expansion of the compiled constants, e.g. later in the pretty printer.
$visitor = new class($allConstInfos) extends PhpParser\NodeVisitorAbstract

... later in that same static function ...

php-src/build/gen_stub.php

Lines 2169 to 2174 in 6329248

$evaluator = new ConstExprEvaluator(
static function (Expr $expr) use ($allConstInfos, &$isUnknownConstValue) {
// $expr is a ConstFetch with a name of a C macro here
if (!$expr instanceof Expr\ConstFetch) {
throw new Exception($this->getVariableTypeName() . " " . $this->name->__toString() . " has an unsupported value");
}

getVariableTypeName() is only something that exists on VariableLike instances so I'm not even sure what the correct replacement should be

PHP Version

6329248

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions