php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54410 Path-related magic constants empty when CLI invoked with -H switch
Submitted: 2011-03-28 17:28 UTC Modified: 2011-06-06 10:14 UTC
From: vedad at kajtaz dot net Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.3.6 OS: FreeBSD 7.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vedad at kajtaz dot net
New email:
PHP Version: OS:

 

 [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
''



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-05 23:23 UTC] iliaa@php.net
-Status: Open +Status: Bogus
 [2011-06-05 23:23 UTC] iliaa@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-06-06 10:14 UTC] 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,
 [2013-04-10 10:04 UTC] spam2 at rhsoft dot net
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;
  }
 }
?>
 [2013-05-08 17:59 UTC] spam2 at rhsoft dot net
so this is now 2 years old and the only repsonse about -H switch doe snot exists is simply bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC