Bug #75542 [Nab]: class not found without opcache loaded
Edit report at https://bugs.php.net/bug.php?id=75542&edit=1
ID: 75542
Updated by: cmb@php.net
Reported by: spam2 at rhsoft dot net
Summary: class not found without opcache loaded
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.2Git-2017-11-20 (Git)
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> [â¦] and could be easily solved at *compile time* [â¦]
A pull request for improvement is welcome.
Previous Comments:
------------------------------------------------------------------------
[2020-12-23 12:16:01] rtrtrtrtrt at dfdfdfdf dot dfd
it is *not* expected behavior that behaves differently when opcache is used with or without
autoloading and could be easily solved at *compile time* even before opcache optimizings
------------------------------------------------------------------------
[2020-12-23 12:08:37] cmb@php.net
This is expected behavior[1]:
| Unless autoloading is used, then classes must be defined before
| they are used. If a class extends another, then the parent class
| must be declared before the child class structure. This rule
| applies to classes that inherit other classes and interfaces.
[1] <https://www.php.net/manual/en/language.oop5.inheritance.php>
------------------------------------------------------------------------
[2017-12-13 07:32:45] ustimenko dot alexander at gmail dot com
Seems to repeats under PHP 7.1.12 (cli)
------------------------------------------------------------------------
[2017-11-20 13:29:00] spam2 at rhsoft dot net
Description:
------------
harry@rh:/downloads]$ php test.php
Fatal error: Uncaught Error: Class 'B' not found in /mnt/data/downloads/test.php:3
Stack trace:
#0 {main}
thrown in /mnt/data/downloads/test.php on line 3
____________________________
[harry@rh:/downloads]$ php-opcache test.php
bla
____________________________
[harry@rh:/downloads]$ cat test.php
<?php declare(strict_types=1);
echo (new B)->test('bla'), "\n";
class B extends A
{
public function test($input): string
{
return parent::test($input);
}
}
class A
{
public function test(string $input): string
{
return $input;
}
}
Test script:
---------------
[harry@rh:/downloads]$ cat test.php
<?php declare(strict_types=1);
echo (new B)->test('bla'), "\n";
class B extends A
{
public function test($input): string
{
return parent::test($input);
}
}
class A
{
public function test(string $input): string
{
return $input;
}
}
Expected result:
----------------
this is a major bug - the class at bottom defined in the same file is explected to be found without
opcache loaded
[harry@rh:/downloads]$ which php
/usr/bin/php
[harry@rh:/downloads]$ which php-opcache
alias php-opcache='/usr/bin/php -d "zend_extension=opcache.so" -d
"opcache.enable_cli=1"'
/usr/bin/php
Actual result:
--------------
class only found when opcache is loaded
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75542&edit=1
Thread (5 messages)