|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: wes9999 at myfastmail dot com
New email:
PHP Version: OS:


 [2012-05-08 17:50 UTC] wes9999 at myfastmail dot com
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. 

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 
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:
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-08 18:31 UTC]
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]
-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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 05:01:34 2024 UTC