php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78881 "Can't preload unlinked class" if class extends Exception
Submitted: 2019-11-28 17:51 UTC Modified: 2019-12-10 12:29 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: mlocati at gmail dot com Assigned: cmb (profile)
Status: Verified Package: opcache
PHP Version: 7.4.0 OS: Windows
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: mlocati at gmail dot com
New email:
PHP Version: OS:

 

 [2019-11-28 17:51 UTC] 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...


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-28 23:06 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-11-28 23:06 UTC] cmb@php.net
Thanks for reporting!
 [2019-12-04 08:45 UTC] 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-12-04 13:54 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2019-12-10 12:16 UTC] michael dot vorisek at email dot cz
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.
 [2019-12-10 12:29 UTC] cmb@php.net
The problem is that internal class entries are stored on the heap,
and the position of the heap is randomized by ASLR on Windows, so
there seems to be nothing we can do (at least for PHP 7.4 due to
BC restrictions).
 [2019-12-13 10:14 UTC] nikic@php.net
The following pull request has been associated:

Patch Name: Remove support for preloading on Windows
On GitHub:  https://github.com/php/php-src/pull/4999
Patch:      https://github.com/php/php-src/pull/4999.patch
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Jan 19 07:01:23 2020 UTC