Error on self::class on non final classes
commit12617287274f0fa6801bf5b8b79f23803219fa8d
authorThomas Jiang <thomasjiang@fb.com>
Tue, 31 Mar 2020 21:01:33 +0000 (31 14:01 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 31 Mar 2020 21:06:17 +0000 (31 14:06 -0700)
tree44fe0d47dd5d1e466d893a3112d11cc70f8db6cb
parent888ab849187a3f6d3b87acba6dcea418032ce2de
Error on self::class on non final classes

Summary:
Error when using `class_meth(self::class, ...)` on a nonfinal class.

While this is not unsafe behavior, it does have unintuitive behavior associated with it. Typically, uses of self::, parent::, and static:: are context forwarding https://www.php.net/manual/en/language.oop5.late-static-bindings.php. However, because self::class resolves (currently) to a string, when we grab it, it loses all of its calling context when we perform the call.

More concretely:

self::foo() and class_meth(self::class, 'foo')() have different behavior when it comes to class context forwarding. This has the biggest implications when discussing function pointers. It would be strange that (self::foo<>)() and self::foo<>() would have different behaviors.

Reviewed By: Wilfred

Differential Revision: D20638089

fbshipit-source-id: 3d157bf5c2c18e6dffbd350d974c2487a6e7ba4e
15 files changed:
hphp/hack/src/errors/error_codes.ml
hphp/hack/src/errors/errors.ml
hphp/hack/src/errors/errors.mli
hphp/hack/src/naming/naming.ml
hphp/hack/src/oxidized/gen/error_codes.rs
hphp/hack/test/errors/error_map.ml
hphp/hack/test/find_refs/rename_static_meth.php
hphp/hack/test/typecheck/class_meth11.php
hphp/hack/test/typecheck/class_meth11.php.exp
hphp/hack/test/typecheck/class_meth13.php [new file with mode: 0644]
hphp/hack/test/typecheck/class_meth13.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/class_meth14.php [new file with mode: 0644]
hphp/hack/test/typecheck/class_meth14.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/class_meth15.php [new file with mode: 0644]
hphp/hack/test/typecheck/class_meth15.php.exp [new file with mode: 0644]