hhvm
hhvm copied to clipboard
Using nameof syntax leads to parse errors
Describe the bug
The code examples on the nameof page lead to parse errors.
Standalone code, or other way to reproduce the problem
class B {}
class C extends B {}
trait T {
require extends B;
public static function f(): void {
var_dump(nameof T); // "T"
var_dump(nameof self); // "D" (user of trait)
var_dump(nameof parent); // "C" (parent of trait user, not B)
var_dump(nameof static); // "E", receiver for ::f() in main
}
}
class D extends C { use T; }
class E extends D {}
<<__EntryPoint>>
function main(): void {
E::f();
}
Steps to reproduce the behavior:
- Copy-paste the above code in
tmp.hackand runhhvm tmp.hack. I tested with the Docker container
Expected behavior
Code should run (or at least parse) properly.
Actual behavior
Fatal error: Encountered unexpected token `T`. in /home/tmp.hack on line 6
Environment
- Operating system: macOS Sonoma 14.2.1
- Installation method: Docker
hhvm/hhvm:latestwithsha256:1cc1be0d469a378114112096431145c9fe80612c61ba48e8697097d933147f60 - HHVM Version
HipHop VM 4.172.0 (rel) (non-lowptr)
Compiler: 1667340154_989010953
Repo schema: 63eaf8b56fb7edbc7a8ca9e32786eb0c1f8f508c
Additional context
We're trying to add support for Hack syntax highlighting in Sourcegraph here: https://github.com/sourcegraph/sourcegraph/pull/62770 and were going through the official docs for code examples.
The version of hhvm you are using is not the latest version. nameof is very new. Your version of hhvm does not support this syntax.
Closing as answered.