Bug #78881 [Com]: "Can't preload unlinked class" if class extends Exception

From: Date: Tue, 10 Dec 2019 12:16:45 +0000
Subject: Bug #78881 [Com]: "Can't preload unlinked class" if class extends Exception
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224190@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78881&edit=1

 ID:                 78881
 Comment by:         michael dot vorisek at email dot cz
 Reported by:        mlocati at gmail dot com
 Summary:            "Can't preload unlinked class" if class extends
                     Exception
 Status:             Verified
 Type:               Bug
 Package:            opcache
 Operating System:   Windows
 PHP Version:        7.4.0
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

This should be fixed in PHP internally. \Exception class is maybe the most extended one and
preloading one or more extended \Exception classes is more than expected.


Previous Comments:
------------------------------------------------------------------------
[2019-12-04 08:54:17] nikic@php.net

I've added an improved error in https://github.com/php/php-src/commit/7cbf31a3c754961e0ebfd5022191c1c9080effdb.

------------------------------------------------------------------------
[2019-12-04 08:45:51] nikic@php.net

This is expected: On Windows, due to ASLR, internal classes are unknown for the purposes of
preloading.

I think the only thing we can do here is a) improve the error message (it should not be
"unknown reason") and b) documented this limitation.

------------------------------------------------------------------------
[2019-11-28 23:06:10] cmb@php.net

Thanks for reporting!

------------------------------------------------------------------------
[2019-11-28 17:51:06] mlocati at gmail dot com

Description:
------------
I have this file, saved as J:\tmp\MyException.php

<?php
class MyException extends Exception {}


I have this file, saved as J:\tmp\preload.php

<?php
opcache_compile_file('J:\\tmp\\MyException.php');


I have this file, saved as J:\tmp\php.ini:

log_errors = On
display_startup_errors = On
extension_dir=C:\Dev\PHP7.4\ext
zend_extension=opcache
opcache.enable_cli=1
opcache.preload=J:\tmp\preload.php


I have downloaded PHP 7.4.0 for Windows, 32 bits, thread safe, to C:\Dev\PHP7.4


If I run this command from the Windows terminal:

C:\Dev\PHP7.4\php.exe -c J:\tmp\php.ini -v

Here's the output:
PHP Warning:  Can't preload unlinked class MyException: Unknown reason in
J:\tmp\MyException.php on line 2

Warning: Can't preload unlinked class MyException: Unknown reason in J:\tmp\MyException.php on
line 2
PHP 7.4.0 (cli) (built: Nov 27 2019 10:15:52) ( ZTS Visual C++ 2017 x86 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies


If I edit the J:\tmp\MyException.php, removing "extends Exception", the output is:

PHP 7.4.0 (cli) (built: Nov 27 2019 10:15:52) ( ZTS Visual C++ 2017 x86 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies


So, it seems that preload doesn't work if a class extends Exception...



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78881&edit=1


Thread (8 messages)

« previous php.bugs (#224190) next »