]> granicus.if.org Git - php/commitdiff
Improve error messages of ext/reflection
authorMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 18 Mar 2020 20:39:56 +0000 (21:39 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 23 Mar 2020 16:23:45 +0000 (17:23 +0100)
Closes GH-5277

ext/reflection/php_reflection.c
ext/reflection/tests/008.phpt
ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt
ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt
ext/reflection/tests/ReflectionMethod_constructor_error1.phpt
ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt
ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
ext/reflection/tests/ReflectionProperty_constructor_error.phpt
ext/reflection/tests/ReflectionReference_errors.phpt

index 94f1b1659dfe0c9b06bf0c06b483c917658c8a23..e3d16fd3e077efd1670dffb175280eeeb3b62856 100644 (file)
@@ -2211,7 +2211,7 @@ ZEND_METHOD(reflection_parameter, __construct)
                        break;
 
                default:
-                       _DO_THROW("The parameter class is expected to be either a string, an array(class, method) or a callable object");
+                       zend_argument_error(reflection_exception_ptr, 1, "must be either a string, an array(class, method) or a callable object, %s given", zend_zval_type_name(reference));
                        RETURN_THROWS();
        }
 
@@ -2876,8 +2876,7 @@ ZEND_METHOD(reflection_method, __construct)
                }
 
                if ((tmp = strstr(name_str, "::")) == NULL) {
-                       zend_throw_exception_ex(reflection_exception_ptr, 0,
-                               "Invalid method name %s", name_str);
+                       zend_argument_error(reflection_exception_ptr, 1, "must be a valid method name");
                        RETURN_THROWS();
                }
                classname = &ztmp;
@@ -2918,7 +2917,7 @@ ZEND_METHOD(reflection_method, __construct)
                        if (classname == &ztmp) {
                                zval_ptr_dtor_str(&ztmp);
                        }
-                       _DO_THROW("The parameter class is expected to be either a string or an object");
+                       zend_argument_error(reflection_exception_ptr, 1, "must be of type object|string, %s given", zend_zval_type_name(classname));
                        RETURN_THROWS();
        }
 
@@ -3457,7 +3456,7 @@ ZEND_METHOD(reflection_class_constant, __construct)
                        break;
 
                default:
-                       _DO_THROW("The parameter class is expected to be either a string or an object");
+                       zend_argument_error(reflection_exception_ptr, 1, "must be of type object|string, %s given", zend_zval_type_name(classname));
                        RETURN_THROWS();
        }
 
@@ -4924,8 +4923,7 @@ ZEND_METHOD(reflection_class, isSubclassOf)
                        }
                        /* no break */
                default:
-                       zend_throw_exception_ex(reflection_exception_ptr, 0,
-                                       "Parameter one must either be a string or a ReflectionClass object");
+                       zend_argument_error(reflection_exception_ptr, 1, "must be of type ReflectionClass|string, %s given", zend_zval_type_name(class_name));
                        RETURN_THROWS();
        }
 
@@ -4967,8 +4965,7 @@ ZEND_METHOD(reflection_class, implementsInterface)
                        }
                        /* no break */
                default:
-                       zend_throw_exception_ex(reflection_exception_ptr, 0,
-                                       "Parameter one must either be a string or a ReflectionClass object");
+                       zend_argument_error(reflection_exception_ptr, 1, "must be of type ReflectionClass|string, %s given", zend_zval_type_name(interface));
                        RETURN_THROWS();
        }
 
@@ -5155,7 +5152,7 @@ ZEND_METHOD(reflection_property, __construct)
                        break;
 
                default:
-                       _DO_THROW("The parameter class is expected to be either a string or an object");
+                       zend_argument_error(reflection_exception_ptr, 1, "must be of type object|string, %s given", zend_zval_type_name(classname));
                        RETURN_THROWS();
        }
 
@@ -6144,7 +6141,7 @@ ZEND_METHOD(reflection_reference, fromArrayElement)
        } else if (Z_TYPE_P(key) == IS_STRING) {
                item = zend_symtable_find(ht, Z_STR_P(key));
        } else {
-               zend_type_error("Key must be array or string");
+               zend_argument_type_error(2, "must be of type string|int, %s given", zend_zval_type_name(key));
                RETURN_THROWS();
        }
 
index 10806b00156602e1eab2a0ee8b388a457e5e0081..0b9a867884eb3f4cd1fb3ecc43b5941dcea2753b 100644 (file)
@@ -27,13 +27,13 @@ foreach ($a as $key=>$val) {
 echo "Done\n";
 ?>
 --EXPECT--
-string(20) "Invalid method name "
-string(21) "Invalid method name 1"
+string(91) "ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name"
+string(91) "ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name"
 string(21) "Class  does not exist"
 string(22) "Class a does not exist"
 string(21) "Class  does not exist"
 string(22) "Class a does not exist"
 string(21) "Class  does not exist"
-string(66) "The parameter class is expected to be either a string or an object"
+string(104) "ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be of type object|string, int given"
 string(21) "Class  does not exist"
 Done
index 7f28198dfab738758df8b3f9a440e7da016b376e..d912b568e8a966b16d06dc0c62bc6e39f0d4ac26 100644 (file)
@@ -65,7 +65,7 @@ try {
     echo $e->getMessage() . "\n";
 }
 ?>
---EXPECTF--
+--EXPECT--
 Does A implement A? 
    - Using object argument: A is not an interface
    - Using string argument: A is not an interface
@@ -146,6 +146,6 @@ Does I2 implement I2?
 Test bad arguments:
 ReflectionClass::implementsInterface() expects exactly 1 parameter, 0 given
 ReflectionClass::implementsInterface() expects exactly 1 parameter, 2 given
-Parameter one must either be a string or a ReflectionClass object
+ReflectionClass::implementsInterface(): Argument #1 ($interface) must be of type ReflectionClass|string, null given
 Interface ThisClassDoesNotExist does not exist
-Parameter one must either be a string or a ReflectionClass object
+ReflectionClass::implementsInterface(): Argument #1 ($interface) must be of type ReflectionClass|string, int given
index b86b70018d47d0ced90ff18fbcbeeec91319c590..6d4ae500a96af5707e6977ec16922c793eca7a54 100644 (file)
@@ -39,6 +39,6 @@ try {
 Test bad arguments:
 ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given
 ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given
-Parameter one must either be a string or a ReflectionClass object
+ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, null given
 Class ThisClassDoesNotExist does not exist
-Parameter one must either be a string or a ReflectionClass object
+ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, int given
index 186c61b2b0fcc0080a1f92402ca2fdde83f2853a..391beced5252707c4405285561f61d6fa93b156a 100644 (file)
@@ -65,17 +65,17 @@ try {
 ?>
 --EXPECTF--
 Wrong type of argument (bool):
-ReflectionException: Invalid method name 1 in %s
+ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name in %s:%d
 Stack trace:
 #0 %s ReflectionMethod->__construct('1')
 #1 {main}
 Wrong type of argument (int):
-ReflectionException: Invalid method name 3 in %s
+ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name in %s:%d
 Stack trace:
 #0 %s ReflectionMethod->__construct('3')
 #1 {main}
 Wrong type of argument (bool, string):
-ReflectionException: The parameter class is expected to be either a string or an object in %s
+ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be of type object|string, bool given in %s:%d
 Stack trace:
 #0 %s ReflectionMethod->__construct(true, 'foo')
 #1 {main}
@@ -85,7 +85,7 @@ Stack trace:
 #0 %s ReflectionMethod->__construct('TestClass', '1')
 #1 {main}
 No method given:
-ReflectionException: Invalid method name TestClass in %s
+ReflectionException: ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be a valid method name in %s:%d
 Stack trace:
 #0 %s ReflectionMethod->__construct('TestClass')
 #1 {main}
index d84fa5dcff5c7e86848a2016c7b5f6a6e8074884..cf0d3bbbaa130a51905204b04a95d493a46a21c2 100644 (file)
@@ -57,5 +57,5 @@ Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
 Too many arguments:
 Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
 Ok - Class InvalidClassName does not exist
-Ok - The parameter class is expected to be either a string or an object
+Ok - ReflectionMethod::__construct(): Argument #1 ($class_or_method) must be of type object|string, array given
 Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given
index 5cebd43016eef2b2abeb842a9b0e175f38b7ce07..30f769aa3dfd41913989f52cc688fb7812464ab4 100644 (file)
@@ -39,6 +39,6 @@ try {
 Test bad arguments:
 ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given
 ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given
-Parameter one must either be a string or a ReflectionClass object
+ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, null given
 Class ThisClassDoesNotExist does not exist
-Parameter one must either be a string or a ReflectionClass object
+ReflectionClass::isSubclassOf(): Argument #1 ($class) must be of type ReflectionClass|string, int given
index ee6ae86cba96ef9e0203e0abda059d2747690265..fd83e30aaa3ff9e8722422f85875baffb8a3c144 100644 (file)
@@ -44,5 +44,5 @@ Class A does not exist
 Method C::b() does not exist
 Method C::b() does not exist
 Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given
-Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object
+Ok - ReflectionParameter::__construct(): Argument #1 ($function) must be either a string, an array(class, method) or a callable object, int given
 Done.
index 38a34681db276c9b49267e4dbb6bc466f396470b..a2df95430947cd4347ea9a5fcd9df77f5a5174be 100644 (file)
@@ -38,7 +38,7 @@ Non-existent class:
 Class NonExistentClass does not exist
 
 Wrong property parameter type:
-The parameter class is expected to be either a string or an object
+ReflectionProperty::__construct(): Argument #1 ($class) must be of type object|string, int given
 
 Non-existent property:
 Property TestClass::$nonExistentProperty does not exist
index 33154ba22ee5d316ca80da91ebd67373ac0705af..88244b79403700e4056dbe17391b72a78bc2f6fb 100644 (file)
@@ -42,7 +42,7 @@ var_dump(unserialize('O:19:"ReflectionReference":0:{}'));
 --EXPECTF--
 Call to private ReflectionReference::__construct() from invalid context
 ReflectionReference::fromArrayElement(): Argument #1 ($array) must be of type array, object given
-Key must be array or string
+ReflectionReference::fromArrayElement(): Argument #2 ($key) must be of type string|int, float given
 Array key not found
 Serialization of 'ReflectionReference' is not allowed