Bug #80000 [Opn->Fbk]: 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: requinix@php.net
Reported by: ASchmidt at Anamera dot net
Summary: Child classes not exist if defined before parent
class
-Status: Open
+Status: Feedback
Type: Bug
Package: Class/Object related
Operating System: Windows x64 IIS
PHP Version: 7.4.9
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2020-08-20 05:47:25] ASchmidt at Anamera dot net
Description:
------------
Produced with a fresh PHP 7.4.9 instance, empty PHP.ini, and a fresh web site.
Child classes that are defined BEFORE the parent class can be referenced by code prior to the class
definitions if running PHP 7.3.21 - but it will FAIL as non-existing in 7.4.9.
I've been struggling with various warnings/errors in WordPress and other code that imply
invalid class/method references, and was finally able to extract the attached reproducable sample.
Test script:
---------------
<?php
declare(strict_types=1);
var_dump( class_exists( 'MySubclass1' ), class_exists( 'MySubclass2' ),
class_exists( 'MyAbstract' ) ); // PHP 7.4.9 = FALSE, true, true (PHP 7.3.21 = TRUE,
true, true)
class MySubclass1 extends MyAbstract{}
abstract class MyAbstract{}
class MySubclass2 extends MyAbstract{}
var_dump( class_exists( 'MySubclass1' ), class_exists( 'MySubclass2' ),
class_exists( 'MyAbstract' ) ); // true, true, true
// Produced with empty php.ini !
Expected result:
----------------
If a child class is defined before or after the parent class should yield consistent results,
whether the child class is referenced earlier or later in the code - as it was in 7.3.
IF it is NOT permitted to define "MySubclass1" before the parent class, then this should
lead to an error at the point the definition is encountered. ACCEPTING the definition as valid but
then producing chance errors depending solely on where the child class is referenced seems arbitrary
when working in large projects.
Actual result:
--------------
Depending on whether the child class was defined before or after the parent, and whether that child
class happens to be referenced before or after its definition, will yield different outcomes (exist
/ not exist)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80000&edit=1
Thread (7 messages)