php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77183 $_SERVER is not set in preloaded classes
Submitted: 2018-11-20 15:38 UTC Modified: 2021-09-26 04:22 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: benjamin dot morel at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: opcache
PHP Version: master-Git-2018-11-20 (Git) OS: Fedora 29
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: benjamin dot morel at gmail dot com
New email:
PHP Version: OS:

 

 [2018-11-20 15:38 UTC] benjamin dot morel at gmail dot com
Description:
------------
When using a preloaded class that references $_SERVER, the variable is not set.
When setting auto_globals_jit to Off, it works.

Test script:
---------------
index.php
========

<?php

header('Content-Type: text/plain');

print_r(Test::getServer());



class.php
=========

<?php

class Test {
        public static function getServer()
        {
                return $_SERVER;
        }
}



preload.php
===========

<?php

opcache_compile_file('class.php');

Expected result:
----------------
Array(
  ...
)

Actual result:
--------------
Notice: Undefined variable: _SERVER in /var/www/html/class.php on line 6

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-21 18:15 UTC] cmb@php.net
Works for me.
 [2018-11-22 10:20 UTC] benjamin dot morel at gmail dot com
Weird. I reproduced it again today with the latest master.

Full reproduce steps:

1. Create /var/www/html/index.php as above
2. Create /var/www/html/class.php as above
3. Create /var/www/html/preload.php as above; change the path to an absolute path:
   opcache_compile_file('/var/www/html/class.php');
4. Add this line to php.ini: opcache.preload = /var/www/html/preload.php
5. Restart php-fpm
6. Load http://localhost/

You should get the error:
Notice: Undefined variable: _SERVER in /var/www/html/class.php on line 6
 [2018-11-22 13:19 UTC] cmb@php.net
> Restart php-fpm

Aha!  I've only tested on CLI; apparently, the issue only affects
some SAPIs.
 [2021-09-14 13:58 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-09-14 13:58 UTC] cmb@php.net
Is this still unresolved with latest PHP 7.4?  If so, would it
work if included class.php (opcache_compile_file() has known
limitations regarding preloading)?
 [2021-09-26 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC