Req #75000 [Nab]: getcwd() does not raise error when it fails

From: Date: Tue, 15 Aug 2017 10:10:42 +0000
Subject: Req #75000 [Nab]: getcwd() does not raise error when it fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210686@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 Updated by: nikic@php.net Reported by: marco dot agnoli at me dot com Summary: getcwd() does not raise error when it fails Status: Not a bug 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: Please don't call people idiots or assholes on this bug tracker. Previous Comments: ------------------------------------------------------------------------ [2017-08-15 10:04:07] spam2 at rhsoft dot net only assholes write code like this $path = \getcwd().'/bin/'; system('rm -rf '.\escapeshellarg($path)); _________________________________ people which not refuse to read docs and listen to people with expirience how to write sane code are doing it that way and would put a fist in your face if you change PHP's behavior to spit in the error log without @ which burries other issues and is a bad style in general P.S.: using namespaces for a 2-liner example with 2 core functions doesn't let you look smarter - the opposite $path = getcwd(); if($path !== false) { // everything rwapped here } else { // do some error handling } ------------------------------------------------------------------------ [2017-08-15 09:58:05] spam2 at rhsoft dot net and how would a warning help here? sorry but the way you argue I highly recommend refrain from developing at all because when you refuse to understand that it is idiotic not to check return values and your last post is just dumb only an idiot is using system() all the time only an idiot is using getcwd() instead __FILE__ to build a path only an idiot allows system() and friends on production servers only an idiot continues to refuse check return values frankly put your fingers away from software - people which argue and write code like you do are the reason for the bad reputation of PHP because every monkey is able to write and publish some crap code and refuses to learn doing it right ------------------------------------------------------------------------ [2017-08-15 02:02:21] marco dot agnoli at me dot com I have thought about this issue once again and actually getcwd can do some serious damage if used incorrectly. I'm aware that it is unlikely for getcwd() to fail but consider the following piece of code: <?php $path = \getcwd().'/bin/'; system('rm -rf '.\escapeshellarg($path)); ?> Since PHP converts false to an empty string the folder we attempt to remove would be "/bin" and we wouldn't even know about it! ------------------------------------------------------------------------ [2017-07-28 10:02:54] spam2 at rhsoft dot net because it would a stupid design when i have to wrap every piece in additional checks or use @ to supress errors which has a large performance impact when a return value you can check is so much more clean Returns the current working directory on success, or FALSE on failure what the hell would you gain when that below triggers a random warning? what you have here is a proper error handling - no thans - i don't want the need to spit @getcwd() all around the code and yes we run error_reporting EALL | E_STRICT for 15 years in production on some hundret customers and the admin group receives every 30 minutes a mail with the current state of the global php error-log - so what you don't want is random warnings with no benefit in a proper environment $cwd = getcwd(); if($cwd !== false) { // do something } else { // properly handle the error } ------------------------------------------------------------------------ [2017-07-28 09:33:01] marco dot agnoli at me dot com I know that it is expected behaviour, but why? Can you tell me the reasoning behind it? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=75000 -- Edit this bug report at https://bugs.php.net/bug.php?id=75000&edit=1

« previous php.bugs (#210686) next »