Edit report at https://bugs.php.net/bug.php?id=54410&edit=1
ID: 54410 Comment by: spam2 at rhsoft dot net Reported by: vedad at kajtaz dot net Summary: Path-related magic constants empty when CLI invoked with -H switch Status: Not a bug Type: Bug Package: CGI/CLI related Operating System: FreeBSD 7.1 PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: besides the fact that this affects also 5.4.13 and there is a -H flag i had yesterday the same problem in CLI-scripts with using __DIR__ and __FILE__ inside of __construct() which i can not really reproduce with my sample code below and it did only happen in CLI mode workaround because i get the same info with the class-name BUT a workaround: FAILED: $this->module_basedir = basename(dirname(__FILE__)); WORKED: $this->module_basedir = substr(__CLASS__, 3); [harry@rh:~]$ php --help | grep Hide -H Hide any passed arguments from external tools __________________________________ [wwwcron@rh:~]$ umask 006; nice -n 19 ionice -c 3 php -H /www/beta.rhsoft.net/classloader/index.php Warning: require(/modules/test/api_test.php): failed to open stream: No such file or directory in on line 8 Fatal error: require(): Failed opening required '/modules/test/api_test.php' (include_path='.:/Volumes/dune/www-servers/phpincludes:/usr/share/pear:/usr/share/php') in on line 8 __________________________________ [wwwcron@rh:~]$ umask 006; nice -n 19 ionice -c 3 php /www/beta.rhsoft.net/classloader/index.php DIRNAME: /mnt/data/www/beta.rhsoft.net/classloader/modules/test test __________________________________ SAMPLE CODE: [harry@rh:/www/beta.rhsoft.net/classloader]$ cat index.php <?php $cl_api = new api_class(); echo $cl_api->test->test('test'); class api_class { public function __get($subclass) { require(__DIR__ . '/modules/' . $subclass . '/api_' . $subclass . '.php'); $class_name = 'cl_' . $subclass; $this->$subclass = new $class_name(); return $this->$subclass; } } ?> [harry@rh:/www/beta.rhsoft.net/classloader]$ cat modules/test/api_test.php <?php class cl_test { public $cl_api; public function __construct() { $this->cl_api = &$GLOBALS['cl_api']; echo 'DIRNAME: ' . dirname(__FILE__) . ' '; } public function test($input_value) { return $input_value; } } ?> Previous Comments: ------------------------------------------------------------------------ [2011-06-06 10:14:15] vedad at kajtaz dot net Hi, The -H flag does exist, and is documented. http://php.net/manual/en/features.commandline.options.php -H Hide any passed arguments from external tools. Regards, ------------------------------------------------------------------------ [2011-06-05 23:23:40] il...@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php there is no -H flag, Using an un-known flag triggers an error condition, which causes PHP to only show the available list of flags and not execute the script. ------------------------------------------------------------------------ [2011-03-28 17:28:05] vedad at kajtaz dot net Description: ------------ When invoking a script with CLI -H switch, __FILE__ and some other magic constants resolve to empty strings. Test script: --------------- # cat > /tmp/test.php <?php var_export(__FILE__); ?> ^D # php /tmp/test.php '/tmp/test.php' # php -H /tmp/test.php '' ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=54410&edit=1