Bug #79474 [Fbk->Nab]: get_declared_classes Wrong loading order Inheritance
| From: | nikic@php.net | Date: | Tue, 14 Apr 2020 16:57:10 +0000 |
| Subject: | Bug #79474 [Fbk->Nab]: get_declared_classes Wrong loading order Inheritance | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226576@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79474&edit=1
ID: 79474
Updated by: nikic@php.net
Reported by: ahwelp at universo dot univates dot br
Summary: get_declared_classes Wrong loading order Inheritance
-Status: Feedback
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 7.4.4
Block user comment: N
Private report: N
New Comment:
Order of get_declared_classes() is unspecified. PHP 7.4, just like previous PHP versions, returns
classes in order of registration. PHP 7.4, unlike previous PHP versions, can register a class before
its parents, if that was the order in which the classes were loaded.
Previous Comments:
------------------------------------------------------------------------
[2020-04-14 16:29:37] requinix@php.net
Is there anything in the official documentation that says they're returned in a particular
order? Besides a user comment from 15 years ago?
------------------------------------------------------------------------
[2020-04-14 11:50:26] ahwelp at universo dot univates dot br
Description:
------------
The function get_declared_classes() should return the loaded classes in the order they were defined.
When a PSR-4 package is required and one class is extended on the local code, the child class is
registered before the parent.
In PHP7.3 the parent is registered before the child.
In PHP7.4x the child is registered before the parent
Test script:
---------------
#composer require jasonlewis/menu dev-master #Small package, good for testing
<?php
include 'vendor/autoload.php';
use JasonLewis\Menu\HtmlBuilder;
class BootstrapBuilder extends HtmlBuilder{}
var_dump(print_r(get_declared_classes(), true));
Expected result:
----------------
Execution on PHP 7.3
string(4086) "Array
(
[0] => stdClass
[1] => Exception
[2] => ErrorException
[3] => Error
.....
[137] => ComposerAutoloaderInitca7fe8d0414cd934e64e09ae5654bee8
[138] => Composer\Autoload\ClassLoader
[139] => Composer\Autoload\ComposerStaticInitca7fe8d0414cd934e64e09ae5654bee8
[140] => JasonLewis\Menu\HtmlBuilder
[141] => BootstrapBuilder
)
Actual result:
--------------
Execution on PHP 7.4
string(4146) "Array
(
[0] => stdClass
[1] => Exception
[2] => ErrorException
......
[138] => ZipArchive
[139] => BootstrapBuilder
[140] => ComposerAutoloaderInitca7fe8d0414cd934e64e09ae5654bee8
[141] => Composer\Autoload\ClassLoader
[142] => Composer\Autoload\ComposerStaticInitca7fe8d0414cd934e64e09ae5654bee8
[143] => JasonLewis\Menu\HtmlBuilder
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79474&edit=1