|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-07-27 23:27 UTC] marcos dot neves at gmail dot com
Description:
------------
Today we have __FILE__ constant, that has the string fileName of the current scrit. Would be nice a constant __MAIN_FILE__, wich has the file name of the first requested PHP file.
So would be possible to do things like this, without use of external library, and is interesting to everyone:
Reproduce code:
---------------
<?
// class File
class Foo {}
if(__MAIN_FILE__ == __FILE__) {
// run some tests and usabe examples with Foo
}
?>
or used to include relative paths to an application, without define constants
<?
// included script
require_once dirname(__MAIN_FILE__) . DIRECTORY_SEPARATOR . "path/to/include/file.php";
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 01:00:02 2025 UTC |
$_SERVER['PHP_SELF'] hasn't the same value using php with apache and php cli. Run <? echo $_SERVER['PHP_SELF'] ?> in a browser and as command line, you'll see the difference. At browser works fine do the follow: if(__FILE__ == $_SERVER['PHP_SELF']) { } but does not work with cli. Tested with PHP 5.1.0b3 on windows XP