Req #46260 [Com]: __FILE__ should not resolve symlink paths

From: Date: Mon, 23 Apr 2012 09:16:36 +0000
Subject: Req #46260 [Com]: __FILE__ should not resolve symlink paths
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-169889@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46260&edit=1

 ID:                 46260
 Comment by:         sdbondi at gmail dot com
 Reported by:        bugs dot php dot net at callum-macdonald dot com
 Summary:            __FILE__ should not resolve symlink paths
 Status:             Open
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   Linux
 PHP Version:        5.2.6
 Block user comment: N
 Private report:     N

 New Comment:

So nothing is being done about this issue?

It seems to have been an issue for at least 6 years without
a adequate solution. 

The behaviour of the __FILE__ constant seems in violation 
of convention and what developers would expect from it.
This bug (yes, bug) prevents us from keeping code (like 
wordpress and a theme) in their own repositories in e.g.
Git (cannot checkout sub-folders - git submodules would 
only work if you didn't want to keep theme build, 
documentation etc. files versioned in the repo). 

I really don't get why this behaviour is not at least configurable.

What is the use case of resolving symlinks? 
I suspect no one would be able to find a use that couldn't
be done in a better way.


Previous Comments:
------------------------------------------------------------------------
[2011-12-28 13:40:41] contato at mesotec dot com dot br

+1 too. I really need this feature.

In windows 7 realpath for a file that is accessed through a mklink folder does return the link path
not the absolute one.

------------------------------------------------------------------------
[2011-12-26 15:51:42] bugs dot php dot net at callum-macdonald dot com

I tested monsen.dag's suggestion and it produced a completely different result than expected.
Also, defining a constant will only apply once, not to the *currently executing file*, which is the
great advantage of __FILE__. This suggestion does not provide a solution of any kind as far as I can
tell.

------------------------------------------------------------------------
[2011-12-22 13:45:24] monsen dot dag at gmail dot com

If you're on an enviroment with bash available, you can use this snippet to get 
__FILE__ without resolving symlinks.

It's a small hack, but it should be pretty safe.

<?php
$output = array();
exec('pwd', &$output);
define('__LINK__', $output[0].substr(__FILE__, strpos(__FILE__, 
DIRECTORY_SEPARATOR)));
?>

------------------------------------------------------------------------
[2011-10-25 19:45:34] nars at clix dot pt

+1

------------------------------------------------------------------------
[2011-07-26 16:54:10] tony at brown dot org

I'm another +1 for this, causing me some real headaches because for deployment I store multiple
versions of a site with the latest been symlinked to for apache.

There are modules in the application which are licensed and use the file path as part of it's
verification. When we deploy, the path is seen as changed and the modules get disabled. :-(

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=46260


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=46260&edit=1


Thread (18 messages)

« previous php.bugs (#169889) next »