diff --git a/src/Parser/ConstantExpressionTrait.php b/src/Parser/ConstantExpressionTrait.php index 86e6adfa..bd787851 100644 --- a/src/Parser/ConstantExpressionTrait.php +++ b/src/Parser/ConstantExpressionTrait.php @@ -139,7 +139,10 @@ trait ConstantExpressionTrait { $class = $this->classDef?->getNamespacedName(false) ?? (($this->namespace ? $this->namespace . '\\' : '') . $this->class); - $function = ($this->namespace ? $this->namespace . '\\' : '') . $this->function; + $function = $this->function; + if ($function !== '' && $this->methodDef === null && $this->namespace !== '') { + $function = $this->namespace . '\\' . $function; + } switch ($expr->getType()) { case 'Scalar_MagicConst_Dir': return '"' . $this->escapeString($this->dir) . '"'; diff --git a/tests/compiler/namespace/magic-function-method.phpt b/tests/compiler/namespace/magic-function-method.phpt new file mode 100644 index 00000000..4aa4c2ea --- /dev/null +++ b/tests/compiler/namespace/magic-function-method.phpt @@ -0,0 +1,34 @@ +--TEST-- +__FUNCTION__ uses the short name in namespaced methods +--FILE-- +instanceMethod(); + \MagicFunctionMethod\Example::staticMethod(); + \MagicFunctionMethod\namespacedFunction(); + } +} +?> +--EXPECT-- +instanceMethod +MagicFunctionMethod\Example::instanceMethod +staticMethod +MagicFunctionMethod\Example::staticMethod +MagicFunctionMethod\namespacedFunction