Bug #75943 [Com]: autoload trying load existing class when it extends not existing class
| From: | akademic at hub dot sknt dot ru | Date: | Fri, 09 Feb 2018 13:20:58 +0000 |
| Subject: | Bug #75943 [Com]: autoload trying load existing class when it extends not existing class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213892@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75943&edit=1
ID: 75943
Comment by: akademic at hub dot sknt dot ru
Reported by: akademic at hub dot sknt dot ru
Summary: autoload trying load existing class when it extends
not existing class
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Ubuntu 16.04.3 LTS
PHP Version: 7.2.2
Block user comment: N
Private report: N
New Comment:
I've understood your first comment completly.
And now I know what happens under the rug. And I've fixed my code now.
I appreciate your help.
Your example (
echo $x; $x = 1;) is about _execution_.
My example (class class_one extends class_two) is about _declaration_. I believe there
is the difference.
I understand technical reasons.
But take a look on this case from PHP-user point.
I have a class:
class class_one {}
And it works perfectly.
Now I change it to class class_one extends class_two {}
My thoughts: I don't have class_two in this file, but I have autoload function, which knows
where class_two is located. So that's ok.
Reality: Fatal error: Class 'class_one' not found. WTF?
I haven't changed the names. I haven't moved code blocks around. I've simply added a
little bit of inheritance and things have gone wrong.
It shouldn't be that. Both situations (with and without inheritance) should fail or both
situations should success.
Previous Comments:
------------------------------------------------------------------------
[2018-02-09 13:14:39] spam2 at rhsoft dot net
no, the bug is clearly that it don't work without because at *compile time* there is no reason
that order matters - that's what compilers are about
the *real* problem anyways is that it behaves different at all while a cache/optimizer should be
fully transparent and not change basic behavior
------------------------------------------------------------------------
[2018-02-09 13:10:32] requinix@php.net
As far as I'm concerned, the bug in your report is that the code works with opcache, not that
it doesn't without.
Frankly I wish we could get rid of the whole "functions/classes can be used before they're
defined" feature.
------------------------------------------------------------------------
[2018-02-09 12:58:56] spam2 at rhsoft dot net
> edge case when it comes to defining classes after they're used
there are a lot of more edge-cases like https://bugs.php.net/bug.php?id=75542 where
obviously opcache takes over way to much of what the compiler should do
"PHP runs files in two steps: a compilation phase where it tries to understand what's in a
file" is skipped in the bugreport above and we talk about just a single file
------------------------------------------------------------------------
[2018-02-09 12:43:39] requinix@php.net
Think about this.
1. PHP cannot have class_one defined without knowing what class_two is, right? Obviously.
2. If class_two does not exist when the file is compiled then class_one cannot be available yet when
it's done.
3. So when PHP starts executing the file, class_one does not exist. It will be only when those lines
of code execute.
4. If you try to use class_one before those lines of code get executed then PHP will do what
it's supposed to do and call the autoloader.
Do you think that this code should work?
echo $x;
$x = 1;
Yeah, refactoring your code has given you more work to do. Welcome to the world of software
development.
------------------------------------------------------------------------
[2018-02-09 12:26:54] akademic at hub dot sknt dot ru
This is so different behavior in almost the same situation.
This is extreamly confusing.
Imagine that you've just written class and it works.
Than you refactor your class and move some functions in parent.
Now all things are broken. And you can't undestand why.
I believe this need to be fixed in PHP.
------------------------------------------------------------------------
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=75943
--
Edit this bug report at https://bugs.php.net/bug.php?id=75943&edit=1