PHP : __FILE__ problem with symbolics links and file path

Problem with symbolic links and __FILE__ variable. __FILE__ won’t show right path instead using real path of symbolic link.

Some time ago I have organized my wordpress plugins via symbolic links. It’s helped me to keep all plugins inside one repository dir and eases me to deploy plugins in different test wordpress locations on my WAMP server. Example of that organization :

d:\plugins\plugin1 // real loaction
d:\plugins\plugin2 // real location
d:\www\wordpress\wp-content\plugins\plugin1 // symbolic link
d:\www\wordpress\wp-content\plugins\plugin2 // symbolic link

Symbolic links are created by :

mklink /D d:\www\wordpress\wp-content\plugins\plugin1 d:\plugins\plugin1

Everything worked well until I have to use __FILE__ varibale. My agony started when I wonted to create plugin with install callback function :

# d:\www\wordpress\wp-content\plugins\plugin1\main.php
register_activation_hook(__FILE__, array( &$plugin, 'install'));

As you can assume this callback function was never triggered. After a while looking at all the wrong places I finally found the problem.

__FILE__ returns real path not the symbolic!

So, in my example output of __FILE__ was : d:\plugins\plugin1\main.php and wordpress is looking for : d:\www\wordpress\wp-content\plugins\plugin1\main.php

I don’t know how __FILE__ behaves in LAMP environment with symbolic links, this is first thing that I am planing to test.

Note to myself: testing in real test environment is far better than that WAMP solution. (By “real test environment” I meant copy of real 😉

Leave a Reply

Your email address will not be published. Required fields are marked *