diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md index 47b76717c839..3a53d0e258ca 100644 --- a/CODING_STANDARDS.md +++ b/CODING_STANDARDS.md @@ -79,6 +79,16 @@ rewritten to comply with these rules. return value for functions that perform some operation that may succeed or fail. +1. When throwing a `ValueError` or emitting a warning, use consistent + phrasing for error messages. Common patterns are: + + * Type errors: `must be of type int` (use the type name, not e.g. `must be an integer`) + * Range/boundary: `must be between X and Y` / `must be greater than [or equal to] X` / `must be less than X` / `must be finite` + * String constraints: `must not contain any null bytes` / `must not be empty` / `must be a single character` + * Valid value: `must be a valid X` (e.g. `must be a valid encoding`, `must be a valid calendar ID`) + * Enum-like: `must be one of X, Y, or Z` + * Structural: `must have X` / `must have key X` / `must have N elements` + ## User functions/methods naming conventions 1. Function names for user-level functions should be enclosed with in the diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index b5109ab6f998..9a05f8e68547 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1054,13 +1054,25 @@ static int do_cli(int argc, char **argv) /* {{{ */ } ZVAL_STRING(&arg, reflection_what); - object_init_ex(&ref, pce); memset(&execute_data, 0, sizeof(zend_execute_data)); execute_data.func = (zend_function *) &zend_pass_function; EG(current_execute_data) = &execute_data; - zend_call_known_instance_method_with_1_params( - pce->constructor, Z_OBJ(ref), NULL, &arg); + // Avoid deprecation warnings from ReflectionMethod::__construct() + // with one argument + if (pce == reflection_method_ptr) { + zend_function *create_from_method = zend_hash_str_find_ptr( + &(pce->function_table), + "createfrommethodname", + strlen( "createFromMethodName" ) + ); + zend_call_known_function( + create_from_method, NULL, pce, &ref, 1, &arg, NULL); + } else { + object_init_ex(&ref, pce); + zend_call_known_instance_method_with_1_params( + pce->constructor, Z_OBJ(ref), NULL, &arg); + } if (EG(exception)) { zval rv; diff --git a/sapi/cli/tests/004.phpt b/sapi/cli/tests/004.phpt index c88b85480bdb..b6e0e74fa6ff 100644 --- a/sapi/cli/tests/004.phpt +++ b/sapi/cli/tests/004.phpt @@ -12,6 +12,9 @@ $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); var_dump(shell_exec("$php -n --rf unknown")); var_dump(shell_exec("$php -n --rf echo")); var_dump(shell_exec("$php -n --rf phpinfo")); +// Regression tests for https://github.com/php/php-src/issues/21754 +var_dump(shell_exec("$php -n --rf ReflectionMethod::__construct")); +var_dump(shell_exec("$php -n --rf ReflectionMethod::missing")); echo "Done\n"; ?> @@ -28,5 +31,16 @@ string(155) "Function [ function phpinfo ] { - Return [ true ] } +" +string(213) "Method [ public method __construct ] { + + - Parameters [2] { + Parameter #0 [ object|string $objectOrMethod ] + Parameter #1 [ ?string $method = null ] + } +} + +" +string(61) "Exception: Method ReflectionMethod::missing() does not exist " Done