The Little Guy Posted October 22, 2009 Share Posted October 22, 2009 I would like to get the directory the current file is in, but all I am getting is nothing... var $dir = __dir__; // this just display __dir__ on the screen // OR var $dir = dirname(__file__); // this displays an error message: Parse error: syntax error, unexpected '(', expecting ',' or ';' why are neither of these methods working? Link to comment https://forums.phpfreaks.com/topic/178566-constants-not-working/ Share on other sites More sharing options...
dreamwest Posted October 22, 2009 Share Posted October 22, 2009 echo getcwd(); Link to comment https://forums.phpfreaks.com/topic/178566-constants-not-working/#findComment-941712 Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 It's __DIR__ (available from PHP 5.3) and __FILE__ http://www.php.net/constants.predefined Link to comment https://forums.phpfreaks.com/topic/178566-constants-not-working/#findComment-941737 Share on other sites More sharing options...
The Little Guy Posted October 22, 2009 Author Share Posted October 22, 2009 If your saying it is because I have them lowercase... These special constants are case-insensitive I found the reason __dir__ doesn't work, its because my php version is 5.2 and it was add 5.3 var $dir = dirname(__file__); doesn't work because I am using it as a property, and I don't believe you can use functions when registering a property. Am I wrong about that? Link to comment https://forums.phpfreaks.com/topic/178566-constants-not-working/#findComment-941785 Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 If your saying it is because I have them lowercase... These special constants are case-insensitive Oh... good catch I found the reason __dir__ doesn't work, its because my php version is 5.2 and it was add 5.3 var $dir = dirname(__file__); doesn't work because I am using it as a property, and I don't believe you can use functions when registering a property. Am I wrong about that? Yeah. You need to do this assignment in constructor. Link to comment https://forums.phpfreaks.com/topic/178566-constants-not-working/#findComment-941789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.