Bug #80000 [NEW]: Child classes not exist if defined before parent class

From: Date: Thu, 20 Aug 2020 05:47:25 +0000
Subject: Bug #80000 [NEW]: Child classes not exist if defined before parent class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228682@lists.php.net to get a copy of this message
From:             ASchmidt at Anamera dot net
Operating system: Windows x64 IIS
PHP version:      7.4.9
Package:          Class/Object related
Bug Type:         Bug
Bug description:Child classes not exist if defined before parent class

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 bug report at https://bugs.php.net/bug.php?id=80000&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80000&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80000&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80000&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80000&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80000&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80000&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80000&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80000&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80000&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80000&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80000&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80000&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80000&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80000&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80000&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80000&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80000&r=mysqlcfg


Thread (7 messages)

« previous php.bugs (#228682) next »