Skip to content

Commit 7b9d6a5

Browse files
MagicalTuxclaude
andcommitted
Fix self/parent/static error messages to match PHP wording
Change "Cannot use X in the global scope" to "Cannot use X when no class scope is active" to match PHP's exact error message format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 319296b commit 7b9d6a5

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

core/compiler/compile-classref.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -819,16 +819,16 @@ func (r *runClassNameOf) Run(ctx phpv.Context) (*phpv.ZVal, error) {
819819
}
820820
cls := ctx.Class()
821821
if cls == nil {
822-
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"self\" in the global scope")
822+
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"self\" when no class scope is active")
823823
}
824824
return phpv.ZString(cls.GetName()).ZVal(), nil
825825
case "parent":
826826
cls := ctx.Class()
827827
if cls == nil {
828828
if ctx.Func() == nil {
829-
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"parent\" in the global scope")
829+
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"parent\" when no class scope is active")
830830
}
831-
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"parent\" in the global scope")
831+
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"parent\" when no class scope is active")
832832
}
833833
parent := cls.GetParent()
834834
if parent == nil {
@@ -854,9 +854,9 @@ func (r *runClassNameOf) Run(ctx phpv.Context) (*phpv.ZVal, error) {
854854
cls := ctx.Class()
855855
if cls == nil {
856856
if ctx.Func() == nil {
857-
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"static\" in the global scope")
857+
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"static\" when no class scope is active")
858858
}
859-
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"static\" in the global scope")
859+
return nil, phpobj.ThrowError(ctx, phpobj.Error, "Cannot use \"static\" when no class scope is active")
860860
}
861861
return phpv.ZString(cls.GetName()).ZVal(), nil
862862
}

0 commit comments

Comments
 (0)