Bug #79956 [NEW]: include_once ignores preloading

From: Date: Tue, 11 Aug 2020 21:09:16 +0000
Subject: Bug #79956 [NEW]: include_once ignores preloading
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228520@lists.php.net to get a copy of this message
From:             crell
Operating system: Linux
PHP version:      7.4.9
Package:          opcache
Bug Type:         Bug
Bug description:include_once ignores preloading

Description:
------------
The list of include/require_once()'ed files seems to not persist between
preloading and regular code run.

Given the 3 files in the test script section, if I run the following:

php -d opcache.preload=preload.php -S localhost:8080

And then view the page in a browser, I would expect to just see "A" in
the output.  Instead, I see:

Including A
A

Indicating the file is really getting executed twice; once in preload,
once in the page request.  However, there's no error about the function
already being defined.

The "Including A" line is shown on the console when the server starts,
indicating it is preloading the file.  If I remove the require_once()
from index.php, the code still runs, confirming it is getting
preloaded.

I don't entirely understand how that combination of results can happen,
as it implies the file is being executed twice but not dying on the
already-declared function.

Test script:
---------------
<?php
# a.php

print "Including A" . PHP_EOL;

function a() {
  print "A" . PHP_EOL;
}
?>

<?php
# preload.php

require_once('a.php');
?>

<?php
# index.php

header('content-type: text/plain');

require_once('a.php');

a();
?>

Expected result:
----------------
The behavior I would expect is that a file require_once()ed in preload
would get skipped entirely if require_once()ed again in the main
application.  That way, I'd be able to have my application
require_once() all of the non-autoloadable files it needs, but then
still toss all of that into preloading for production and have it just
"get faster."  Whatever is happening in those files should only happen
the one time, period.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=79956&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79956&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79956&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79956&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79956&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79956&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79956&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79956&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79956&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79956&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79956&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79956&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79956&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79956&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79956&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79956&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79956&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79956&r=mysqlcfg


Thread (3 messages)

« previous php.bugs (#228520) next »