php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61975 magic constant __FILE__ is fixed, even if directory is renamed
Submitted: 2012-05-08 17:50 UTC Modified: 2012-05-08 18:31 UTC
From: wes9999 at myfastmail dot com Assigned:
Status: Not a bug Package: APC (PECL)
PHP Version: Irrelevant OS: redhat enterprise
Private report: No CVE-ID: None
 [2012-05-08 17:50 UTC] wes9999 at myfastmail dot com
Description:
------------
When running APC, if a script uses the __FILE__ magic constant to determine the 
full directory name of where the script is running from, it will continue to get 
the same directory, even if the directory of the script is renamed. 

Example:
Place the test script in a directory named "mydir1" and access the script with a 
browser.  Then, in the directory above mydir1, type "mv mydir1 mydir2" to rename 
the directory.  If you access the script now, it will not be found.  If you then 
change the url to reference the script in the proper directory of mydir2, it 
will 
be found, however, it will report the __FILE__ magic constant to be mydir1.

This can cause issues if one uses __FILE__ when including other scripts, as they 
won't be found after the directory is renamed, until the APC cache is cleared or 
the script's timestamp is modified.

I tried running this on a server without APC and it behaved as expected.


Test script:
---------------
<?php
echo ' hello '.date('r').'<br/>';
echo ' magic constant __FILE__  '.__FILE__."<br/>";
?>


Expected result:
----------------
I expect it to output the correct full path to the script

Actual result:
--------------
It outputs the path of the script as it was before renaming the directory.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-08 18:31 UTC] rasmus@php.net
This really isn't a bug. __FILE__ is a script compile-time constant and APC 
caches the compiled scripts. You need to be aware of this when you use APC. If 
you are going to renamed directories and move stuff around, clear your cache.
 [2012-05-08 18:31 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-09-22 09:56 UTC] isidoros dot anthemios at gmail dot com
If this is not a "bug" this is a serious limitation.
APC caches each file according to the inode.
So if the file is hardlinked, ou "-o bind" mounted,
the file ( or a whole filesystem, or a whole subdirectory ) 
will exist in SEVERAL paths with the SAME inode.

In my opinion this is a bug in the sense that apc believes that inode == path.
This is obviously not true in the posix world.
This might be considered some kind of "optimization", but in this case it should 
be possible to "opt out" from it.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 23 08:01:24 2021 UTC