php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75542 class not found without opcache loaded
Submitted: 2017-11-20 13:29 UTC Modified: 2020-12-23 12:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: spam2 at rhsoft dot net Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2Git-2017-11-20 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spam2 at rhsoft dot net
New email:
PHP Version: OS:

 

 [2017-11-20 13:29 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-13 07:32 UTC] ustimenko dot alexander at gmail dot com
Seems to repeats under PHP 7.1.12 (cli)
 [2020-12-23 12:08 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-12-23 12:08 UTC] 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>
 [2020-12-23 12:16 UTC] 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:29 UTC] cmb@php.net
> […] and could be easily solved at *compile time* […]

A pull request for improvement is welcome.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jun 22 15:01:24 2021 UTC