Bug #80000 [Opn->Wfx]: Child classes not exist if defined before parent class
Edit report at https://bugs.php.net/bug.php?id=80000&edit=1
ID: 80000
Updated by: cmb@php.net
Reported by: ASchmidt at Anamera dot net
Summary: Child classes not exist if defined before parent
class
-Status: Open
+Status: Wont fix
Type: Bug
Package: Class/Object related
Operating System: Windows x64 IIS
PHP Version: 7.4.9
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
From a recent blog post by Nikita[1]:
| After reading this blog post, youâll probably appreciate why bug
| reports related to early binding go right on the âwonât fixâ pile.
So, yeah.
[1] <https://www.npopov.com/2021/10/20/Early-binding-in-PHP.html>
Previous Comments:
------------------------------------------------------------------------
[2020-09-01 19:03:36] fgfgfgfgfg at gmail dot com
there are even behavior differences with or without opcache loaded which is a bad sign given that
PHP is not bash where a script is read line-by-line while it runs and beware god you change
something and press save
------------------------------------------------------------------------
[2020-09-01 19:01:03] huynhat dot niit at gmail dot com
The following pull request has been associated:
Patch Name: Ignore externally managed and generated files
On GitHub: https://github.com/php/web-windows/pull/21
Patch: https://github.com/php/web-windows/pull/21.patch
------------------------------------------------------------------------
[2020-08-20 09:09:48] cmb@php.net
This is documented[1] behavior:
| Unless autoloading is used, then classes must be defined before
| they are used. If a class extends another, then the parent class
| must be declared before the child class structure.
The fact that the engine is more permissible in certain cases, is
nothing code should rely upon; if you define multiple classes in
the same file, put them in the proper order. On the other hand,
we cannot change the current behavior in stable release branches,
for BC reasons.
We *may* error on potentially unsupported class order in PHP 8,
but I see no particular point in doing so.
[1] <https://www.php.net/manual/en/language.oop5.inheritance.php>
------------------------------------------------------------------------
[2020-08-20 07:04:43] ASchmidt at Anamera dot net
Thank you! I followed your lead and found out - it's being "masked" by OpCache!
IF OpCache is running (in my production 7.3.21), then the output is "true/true/true" - but
I had been turning off extensions in 7.4.9 to track down nyriad other errors - which then exposed
the reported behavior, further adding to the confusion.
I now understand that this was NOT due to a recent change. However, I now feel even stronger that
this is far from being handled "transparently", given all the various factors interacting
to create ambiguity.
If a child class only works "sometimes" -- when all the stars align correctly, then I feel
this should be rejected outright at the place where the child class is defined. If the only
consistent "working" pattern requires the child class to FOLLOW the parent class, then PHP
should enforce that sequence and not permit child classes before parent classes.
------------------------------------------------------------------------
[2020-08-20 05:52:44] requinix@php.net
Doesn't look like anything's changed recently. https://3v4l.org/bIF1m
MySubclass1 can't be defined early because it depends on MyAbstract which isn't available
yet. MySubclass2 doesn't have that problem.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=80000
--
Edit this bug report at https://bugs.php.net/bug.php?id=80000&edit=1
Thread (7 messages)