php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78925 Can't preload class ... with unresolved initializer for property ...
Submitted: 2019-12-07 22:18 UTC Modified: 2019-12-09 08:53 UTC
From: nexor1984 at gmail dot com Assigned: dmitry (profile)
Status: Not a bug Package: opcache
PHP Version: 7.4.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nexor1984 at gmail dot com
New email:
PHP Version: OS:

 

 [2019-12-07 22:18 UTC] nexor1984 at gmail dot com
Description:
------------
Trying to preload a file like:
<?php
define('PEAR_ERROR_RETURN',     1);

class PEAR_Error
{
    var $mode                 = PEAR_ERROR_RETURN;
}


gives an error:
PHP Warning:  Can't preload class PEAR_Error with unresolved initializer for property $mode in /var/www/html/phptest/lib/pear/PEAR.php on line 5



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-08 07:48 UTC] nikic@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: dmitry
 [2019-12-08 07:48 UTC] nikic@php.net
Constants are not preloaded, you cannot preload classes making use of (non-internal) constants in initializers.

@dmitry: I don't quite remember why we can't preload constants, what was the reason for this?
 [2019-12-08 12:41 UTC] beberlei@php.net
It looks like its working when you declare the constant directly in the preloading script and then opcache_compile_file with the class where its used.

The script with the global constant must be executed, not just opcache_compile_file'd. 

https://gist.github.com/beberlei/67cb3682af3cf6599307765cd30c5222

It looks like that even handles the case where the script redeclares the constant with define.
 [2019-12-08 12:46 UTC] nikic@php.net
-Summary: Can't preload class ... with unresolved initializer for property ... +Summary: Side-effects for uninitialised typed property
 [2019-12-08 12:46 UTC] nikic@php.net
@beberlei: That looks like a bug :( As we won't actually restore the constant value, it might be defined to some other value, rendering the constexpr evaluation incorrect.
 [2019-12-08 12:46 UTC] nikic@php.net
-Summary: Side-effects for uninitialised typed property +Summary: Can't preload class ... with unresolved initializer for property ...
 [2019-12-09 08:53 UTC] dmitry@php.net
@nikic constants are defined at runtime and even worse - define() may fail with a notice. There were a related RFC https://wiki.php.net/rfc/constant_redefinition

@beberlei the class may be loaded with opcache.optimizarion_level=-1 (this enables unsafe optimizations).
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 19:03:40 2021 UTC