adredz Posted November 21, 2009 Share Posted November 21, 2009 I have started studying PHP...pls explain to me...thanks Quote Link to comment Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 The function dirname simply returns the directory from a full path, so for example c:\something\something\file.php would return c:\something\something\. _FILE_ is a magic constant that simply returns the path of the current file. The second bit, dirname(ABSPATH), appears to use a user defined constant 'ABSPATH' (to my knowledge it's not a generic PHP one), it would probably require a line of code along the lines of define('ABSPATH', __FILE__);. Quote Link to comment Share on other sites More sharing options...
Mcfarlin Posted November 21, 2009 Share Posted November 21, 2009  yes    define(’ABSPATH’, dirname(__FILE__).’/');  could be used where ABSPATH would get you the absolute path to the file location within your directory  The __FILE__ returns the full path and filename of the file accomplished by dirname() which returns directory name component of path.   i have been up for a few to many hours tho so not at 100% here. lol Quote Link to comment Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 i have been up for a few to many hours tho so not at 100% here. lol  I guess it's lucky I already answered then really isn't it. Quote Link to comment Share on other sites More sharing options...
adredz Posted November 21, 2009 Author Share Posted November 21, 2009  yes    define(’ABSPATH’, dirname(__FILE__).’/');  could be used where ABSPATH would get you the absolute path to the file location within your directory  The __FILE__ returns the full path and filename of the file accomplished by dirname() which returns directory name component of path.   i have been up for a few to many hours tho so not at 100% here. lol I am sorry I am a bit confused. So if this line of code "define(’ABSPATH’, dirname(__FILE__).’/');" is under something.php, does it mean the _FILE_ pertains to something.php? And does the .'/' pertains to current directory? Quote Link to comment Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 Yes __FILE__ will be the path of something.php, take into account that if you use it in a script that is include'd in another script it will return the filename of the file the line is written in not the file that included it. './' in html would mean up one directory and should be before a path, I have no idea why Mcfarlin used it there. Quote Link to comment Share on other sites More sharing options...
adredz Posted November 21, 2009 Author Share Posted November 21, 2009 './' in html would mean up one directory and should be before a path, I have no idea why Mcfarlin used it there. Â I am actually trying to absorb the wordpress source code and learn php from it. =) Under the file wp-load.php is this line: define( 'ABSPATH', dirname(__FILE__) . '/' ); Â What could .'/' mean? Â Though here's another line which makes sense to me: ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) Â Here, wp-config.php is on the same dir as wp-load.php. Given the ABSPATH is c:/something/something, putting it as a parameter of dirname() makes it c:/something now right? And you said .'/' is up one directory, so file_exists() is actually looking into the right path... So could it be that define( 'ABSPATH', dirname(__FILE__) . '/' ); is incorrect syntax wise? Â Please correct me if I am wrong. I have a feeling my assumption here is entirely wrong! =) Â Quote Link to comment Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 Oh sorry my bad, the font seems a bit smaller since the last update I thought it was './' not just a slash. I think in my first post I listed the output of dirname having a trailing slash, which it doesn't. In my first example the output should have been 'c:\something\something'. All that code does is stores the directory that the file is contianed in (complete with trialing slash), into a constant called ABSPATH. The dot between dirname() and the '/' simply means concatinate that slash on the end of the path returned. Quote Link to comment Share on other sites More sharing options...
adredz Posted November 21, 2009 Author Share Posted November 21, 2009 Thanks. It's clearer now. ONe last question. What's the difference between ( file_exists( ABSPATH . 'wp-config.php') ) and ( file_exists( dirname(ABSPATH) . '/wp-config.php' )? Quote Link to comment Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 There isn't one. But I have to say I don't see the point of the second example. Why use dirname to get a path concatinate '/' to the end of it and store it in ABSPATH only to then call dirname on it again and add the forward slash in the second part. Basically you have redundant code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.