php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68133 Fatal error: require_once/include_once when using reference
Submitted: 2014-10-02 17:31 UTC Modified: 2014-10-02 17:38 UTC
From: pegasus at vaultwiki dot org Assigned:
Status: Closed Package: *General Issues
PHP Version: master-Git-2014-10-02 (Git) OS: Centos 6
Private report: No CVE-ID: None
 [2014-10-02 17:31 UTC] pegasus at vaultwiki dot org
Description:
------------
When require_once($x) is used inside a method that takes $x as an argument by reference, the following error occurs:

Fatal Error: require_once(): Failed opening '0`^,' ...

If ZendOpcache is enabled, only:

Fatal Error: require_once

Checking the value of $x on the preceding line shows the correct value, and file_exists($x) on the proceeding line shows that PHP can find the file.

If we do $y = $x; require_once($y); instead, or remove the reference, then the fatal error is bypassed.

However, there are cases in the full use case where it is useful to change the required file within the method, and then have external access to the new filename thanks to the reference.

Some notes: In the particular cases I've tested, the files have all been inside a symlinked directory, but I doubt that is related since it works if the reference is removed.

Test script:
---------------
class Test
{
public static function load(&$file)
{
require_once($file);
}
}

$file = '/path/through/symlinked/directory/to/file';

// symlink is owned by root:root with 777 permissions
// target directory is owned by PHP-run-as user

Test::load($file);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-02 17:38 UTC] pegasus at vaultwiki dot org
-Summary: Fatal error: require_once/include_once +Summary: Fatal error: require_once/include_once when using reference
 [2014-10-02 17:38 UTC] pegasus at vaultwiki dot org
Updated title
 [2014-10-03 19:09 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e7623f470f3c43396db4adcceeb63bd7029bc5ff
Log: Fix bug #68133 and bug #68135
 [2014-10-03 19:09 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2014-10-05 17:50 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e7623f470f3c43396db4adcceeb63bd7029bc5ff
Log: Fix bug #68133 and bug #68135
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e7623f470f3c43396db4adcceeb63bd7029bc5ff
Log: Fix bug #68133 and bug #68135
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC