Req #75000 [Com]: getcwd() does not raise error when it fails
| From: | marco dot agnoli at me dot com | Date: | Fri, 28 Jul 2017 06:12:41 +0000 |
| Subject: | Req #75000 [Com]: getcwd() does not raise error when it fails | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210382@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75000&edit=1
ID: 75000
Comment by: marco dot agnoli at me dot com
Reported by: marco dot agnoli at me dot com
Summary: getcwd() does not raise error when it fails
Status: Open
Type: Feature/Change Request
Package: *General Issues
Operating System: OS X
PHP Version: 7.1.7
Block user comment: N
Private report: N
New Comment:
Same can be said for the
realpath function:
```
<?php
error_reporting(E_ALL);
var_dump(realpath('non-existing-path'));
?>
```
realpath() expects a valid path, so why not raise an error when no valid path was specified?
Previous Comments:
------------------------------------------------------------------------
[2017-07-28 06:09:04] marco dot agnoli at me dot com
Description:
------------
Some functions like chdir() raise an error when they fail, but others like getcwd() don't.
I don't see why getcwd() should not raise an error.
This makes catching errors more painful than it should be.
Test script:
---------------
<?php
var_dump(getcwd());
// Remove traversal permission for the current directory
system('chmod -x '.escapeshellarg(__DIR__));
/**
* I would expect an error here
* because getcwd() returns false here.
*/
var_dump(getcwd());
// Restore traversal permission
system('chmod +x '.escapeshellarg(__DIR__));
?>
Expected result:
----------------
A warning from PHP that getcwd() failed.
Actual result:
--------------
getcwd() silently returns false.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75000&edit=1