Re: PHP 8 is_file/is_dir input handling

From: Date: Tue, 01 Dec 2020 19:50:13 +0000
Subject: Re: PHP 8 is_file/is_dir input handling
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-112353@lists.php.net to get a copy of this message
Hi!
In PHP 7, this returns FALSE: php -r 'var_dump(is_file("ab\0c"));' In PHP 8, the same code throws a ValueException. Problem is now that
I think this is a mistake. Exceptions should not be thrown on such values, it only breeds boilerplate code (now you'd have to wrap each call to is_* into try/catch or add another pre-call validator just to ensure it doesn't throw). PHP type system is not robust enough to support fine-grained types like "string that has certain format", and pretending we do have this as a type and throwing typing error on it only makes the consumer work harder for no additional gain. In almost every situation I can imagine, string that is not the name of the file is equivalent to string that is not the name of the file and also has \0 in it. However, this setup forces me to treat them differently and add additional validation step to it. While to some functions it may be a useful functionality - specifically to constructor functions expected to return an object, so they can't really tell "you gave me invalid data" other than throwing - for something like is_file it will only be annoying. -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#112353) next »