Bug #70651 [Opn->Nab]: Inconsistent usage of Current Working Directory
| From: | ab@php.net | Date: | Wed, 07 Oct 2015 14:06:06 +0000 |
| Subject: | Bug #70651 [Opn->Nab]: Inconsistent usage of Current Working Directory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196451@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70651&edit=1
ID: 70651
Updated by: ab@php.net
Reported by: deivid dot garcia dot garcia at gmail dot com
Summary: Inconsistent usage of Current Working Directory
-Status: Open
+Status: Not a bug
Type: Bug
Package: Directory function related
Operating System: Windows/IIS/FastCGI
PHP Version: 7.0.0RC4
Block user comment: N
Private report: N
New Comment:
Thanks for the report. This behavior is documented and is unlikely to be changed. PHP depends on the
C runtime in cases like this. Besides SAPIs changing CWD, any external extension could do it.
That's where PHP core is not in control of this kind of change. An obvious solution in many
cases is just using absolute paths.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2015-10-06 15:15:21] deivid dot garcia dot garcia at gmail dot com
Just as a final note, having the current working directory change on shutdown functions is an
unpleasant but described behaviour in the PHP docs for some web servers.
But I expect is_dir and is_file to make a consistent usage of what the current working directory is.
------------------------------------------------------------------------
[2015-10-06 15:11:05] deivid dot garcia dot garcia at gmail dot com
Using reroute_enabled = 1 in the php ini setting for the Wincache extension yields further
inconsistent results.
When $test == 2
Actual Output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
is_file(php.exe): false
is_file(cron.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
is_file(php.exe): true
is_file(cron.php): true
Expected Output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
is_file(php.exe): false
is_file(cron.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): false
is_dir(sites/default): false
is_file(index.php): false
is_file(php.exe): true
is_file(cron.php): false
When $test == 1
Actual Output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
Expected Output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): false
is_dir(sites/default): false
is_file(index.php): false
------------------------------------------------------------------------
[2015-10-06 15:04:29] deivid dot garcia dot garcia at gmail dot com
Description:
------------
is_dir and is_file are returning inconsistent results when being called from code registered by
register_shutdown_function().
Test script:
---------------
<?php
function printline($line) { echo $line . "<br/>\r\n"; }
function _is_dir($dir) { printline("is_dir({$dir}): " . (is_dir($dir) ? "true" :
"false")); }
function _is_file($file) { printline("is_file({$file}): " . (is_file($file) ?
"true" : "false")); }
global $test;
$test = 1;
function test_dir() {
global $test;
printline("workding directory:" . getcwd());
// sites/all is a regular directory in the webroot
_is_dir('sites/all');
// sites/default is a symlink directory in the webroot
_is_dir('sites/default');
// index.php is where this script in the webroot
_is_file('index.php');
if ($test == 2) {
// php.exe not in webroot
_is_file('php.exe');
// cron.php is a file in the webroot
_is_file('cron.php');
}
}
test_dir();
printline("shutdown");
register_shutdown_function('test_dir');
return;
Expected result:
----------------
When $test == 1
Actual output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): false
is_dir(sites/default): false
is_file(index.php): true
Expected Output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): false
is_dir(sites/default): false
is_file(index.php): false
When $test == 2
Actual Output = Expected Output:
workding directory:D:\REPOSITORIOS_SABENTIS\drupal7
is_dir(sites/all): true
is_dir(sites/default): true
is_file(index.php): true
is_file(php.exe): false
is_file(cron.php): true
shutdown
workding directory:C:\Program Files (x86)\PHP\php5.6
is_dir(sites/all): false
is_dir(sites/default): false
is_file(index.php): false
is_file(php.exe): true
is_file(cron.php): false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70651&edit=1