php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77649 preload: Can't preload class %s with unresolved initializer for constant
Submitted: 2019-02-21 22:33 UTC Modified: 2019-12-13 10:13 UTC
From: mberchtold at gmail dot com Assigned:
Status: Wont fix Package: opcache
PHP Version: master-Git-2019-02-21 (snap) OS: Windows 10 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-02-21 22:33 UTC] mberchtold at gmail dot com
Description:
------------
This is related to the bug that was reported (and fixed) here:
https://bugs.php.net/bug.php?id=77643

Basically I'm trying to preload some parts of zend framework 3 and the following warning is logged:
PHP Warning:  Can't preload class Zend\Db\Sql\Select with unresolved initializer for constant JOIN_LEFT_OUTER at vendor\zendframework\zend-db\src\Sql\Select.php:21 in Unknown on line 0

The constant is defined as following in Select.php
    const JOIN_LEFT_OUTER  = Join::JOIN_LEFT_OUTER;

where JOIN_LEFT_OUTER is defined in Join.php:
    const JOIN_LEFT_OUTER  = 'left outer';

Test script:
---------------
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/preload_undef_const_5.inc

preload_undef_const_5.inc:

<?php
$basedirectory = 'C:/test/';
// dependent classes
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/Join.php');
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/AbstractPreparableSql.php');
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/AbstractSql.php');
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/SqlInterface.php');
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/PreparableSqlInterface.php');
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/Platform/PlatformDecoratorInterface.php');

// actual class
opcache_compile_file($basedirectory . 'vendor/zendframework/zend-db/src/Sql/Select.php');


Expected result:
----------------
no warning

Actual result:
--------------
PHP Warning:  Can't preload class Zend\Db\Sql\Select with unresolved initializer for constant JOIN_LEFT_OUTER at vendor\zendframework\zend-db\src\Sql\Select.php:21 in Unknown on line 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-22 08:25 UTC] nikic@php.net
I'm not able to reproduce this.
 [2019-02-22 15:55 UTC] mberchtold at gmail dot com
Let me help you with this:

1. Use PHP on Windows 10 64-bit
2. Download the latest snap (today) from here: https://windows.php.net/downloads/snaps/master/r7cf177c/php-master-nts-windows-vc15-x64-avx-r7cf177c.zip
3. Create a file called preload.php and use the code from the script in this bug report.
4. Download zend-db from here: https://codeload.github.com/zendframework/zend-db/zip/master and extract the zip
5. Change the $basedirectory in the preload.php pointing to correct location of the zend-db in 4.
6. change php ini values:
opcache.enable_cli=1
opcache.preload=preload.php
7. run php.exe
 [2019-02-22 16:15 UTC] nikic@php.net
So, good news is that I can indeed reproduce this on Windows. However, I can't debug it there, and it doesn't repro on Ubuntu. Not immediately obvious to me why this would be OS dependent either.
 [2019-02-22 16:21 UTC] nikic@php.net
-Assigned To: +Assigned To: dmitry
 [2019-02-22 16:21 UTC] nikic@php.net
Ah wait, I see it now. There's another warning on Windows:

Warning: Can't preload unlinked class Zend\Db\Sql\Join at D:\htdocs\zend-db-master\src\Sql\Join.php:25 in Unknown on line 0

And this is the class declaration: https://github.com/zendframework/zend-db/blob/master/src/Sql/Join.php#L25

I guess that we don't support linking of internal classes on Windows due to ASLR issues.
 [2019-02-22 16:25 UTC] nikic@php.net
-Status: Assigned +Status: Open -Assigned To: dmitry +Assigned To:
 [2019-02-22 16:25 UTC] nikic@php.net
Sorry, accidental assignment.
 [2019-12-13 10:13 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2019-12-13 10:13 UTC] nikic@php.net
Per previous comment, this is a Windows ASLR issue, which I don't believe we can avoid. We may instead disable preloading on Windows entirely, see https://github.com/php/php-src/pull/4999.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC