Bug #78124 [Opn->Fbk]: Subclass of an included class not available
| From: | nikic@php.net | Date: | Fri, 07 Jun 2019 19:27:00 +0000 |
| Subject: | Bug #78124 [Opn->Fbk]: Subclass of an included class not available | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221182@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78124&edit=1
ID: 78124
Updated by: nikic@php.net
Reported by: aschmidt at anamera dot net
Summary: Subclass of an included class not available
-Status: Open
+Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Win x64
PHP Version: 7.2.19
Block user comment: N
Private report: N
New Comment:
You likely have opcache enabled on one version and disabled on the other. Is that the case?
Previous Comments:
------------------------------------------------------------------------
[2019-06-07 19:02:23] aschmidt at anamera dot net
Description:
------------
If a class extends a parent class from an include/require, then the subclass cannot be referenced
until AFTER the class definition.
However, if a class extends a parent class from the SAME script, then the subclass CAN be referenced
anywhere in the code.
I can't tell at what point this broke, but this appears to have worked in earlier 7.2 releases.
Test script:
---------------
<?php
declare(strict_types=1);
require( 'bug2.php' );
// Error: mySubClass2 does NOT exist!
var_dump( class_exists( 'myClass1', FALSE ), class_exists( 'mySubClass1', FALSE
), class_exists( 'myParentClass', FALSE ), class_exists( 'mySubClass2', FALSE )
);
class myClass1 {
const myConst = 'C1';
}
class mySubClass1 extends myClass1 {
const myConst = 'S1';
}
class mySubClass2 extends myParentClass {
const myConst = 'S2';
}
// Correct: Now mySubClass2 DOES exist!
var_dump( class_exists( 'myClass1', FALSE ), class_exists( 'mySubClass1', FALSE
), class_exists( 'myParentClass', FALSE ), class_exists( 'mySubClass2', FALSE )
);
Content of file "bug2.php":
<?php
declare(strict_types=1);
class myParentClass {
const myConst = 'Parent';
}
Expected result:
----------------
subclass_bug.php:7:boolean true
subclass_bug.php:7:boolean true
subclass_bug.php:7:boolean true
subclass_bug.php:7:boolean true
Actual result:
--------------
subclass_bug.php:7:boolean true
subclass_bug.php:7:boolean true
subclass_bug.php:7:boolean true
subclass_bug.php:7:boolean false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78124&edit=1