Re: Re: PHP 8 is_file/is_dir input handling
| From: | Rowan Tommins | Date: | Tue, 01 Dec 2020 20:35:14 +0000 |
| Subject: | Re: Re: PHP 8 is_file/is_dir input handling | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112361@lists.php.net to get a copy of this message | ||
On 01/12/2020 20:06, Stanislav Malyshev wrote:
The posted code is correct under a theoretical version of is_file() that returns false for that input, but it is incorrect for all versions of PHP after PHP 5.4, since they return null (as shown by the sample posted by George: https://3v4l.org/7E2mv) so the ===false condition will not be met. I think we can all agree that the previous behaviour was less than ideal - the NULL return value was undocumented and unexpected, and the wording of the Warning was pretty vague. If I'd never seen this discussion, I think my assumption would be that invalid input would simply return false in this particular case - if the path is logically impossible, then it's not a file. However, I wonder if there other functions also use this undocumented "file path" input type, where there isn't such an obvious safe return value, and throwing an exception is more justifiable. Regards, -- Rowan Tommins (né Collins) [IMSoP]is broken is a great illustration of that. PHP 8 makes it obvious that the cited code is incorrect.But it's not incorrect. if is_file("abc\0") returns false, it's correct - "abc\0" is not a correct filename, so I expect it to return false. It does exactly what I need, so it's correct.