On 01/12/2020 20:06, Stanislav Malyshev wrote:
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.
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]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php