|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-28 17:28 UTC] 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
''
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 02:00:01 2025 UTC |
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; } } ?>