-
-
Notifications
You must be signed in to change notification settings - Fork 521
Description
The WordPress.WP.AlternativeFunctions sniff suggests WP functions that should be used instead of native PHP functions. In the case of file_get_contents(), file_put_contents(), fopen(), and readfile(), this recommendation depends on the parameter values.
The sniff currently bows out when a resource is passed as the first parameter (STDIN, STDOUT, STDERR), but this is incorrect because these functions only accept string filenames, not resources. Code like fopen(STDIN, 'w') results in a fatal error: "Uncaught TypeError: fopen(): Argument #1 ($filename) must be of type string, resource given" (https://3v4l.org/vkbB4).
There are a few code examples, like the one above, in the sniff tests. They were introduced in #1655. Unless I'm missing something, I don't see a reason for the sniff to have special handling for invalid code. If that is indeed the case, this condition can be removed:
| || isset( $this->allowed_local_stream_constants[ $clean_param_value ] ) |
Removing the condition above means that the sniff will start triggering a warning for the code sample presented in this issue, which I believe is the correct behavior.
Initially discussed in #2581 (comment)