Hello everyone,


I have created a simple patch that extends PHP ReflectionException

Messages in the case of a missing property or method when calling:



$reflClass->getProperty('notKnown');

$reflClass->getMethod('notKnown');



Currently, in both cases only the unknown property and method names are

referenced but not the class-name. In our Doctrine 2

code basis, where we use Reflection heavily this can be pretty annoying

for users to debug, since there is no context to check

against.



The interesting portion of the patch is here, the whole patch file

contains changes to the test-cases also:



Index: ext/reflection/php_reflection.c

===================================================================

--- ext/reflection/php_reflection.c     (revision 296963)

+++ ext/reflection/php_reflection.c     (working copy)

@@ -3425,7 +3425,7 @@

        } else {

                efree(lc_name);

                zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 

-                               "Method %s does not exist", name);

+                               "Method %s::%s() does not exist", ce->name, 
name);

                return;

        }

 }

@@ -3602,7 +3602,7 @@

                }               

        }

        zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 

-                       "Property %s does not exist", name);

+                       "Property %s::%s does not exist", ce->name, name);

 }

 /* }}} *



The patch is against SVN trunk.



greetings,

Benjamin
Index: ext/reflection/tests/ReflectionClass_getProperty_002.phpt
===================================================================
--- ext/reflection/tests/ReflectionClass_getProperty_002.phpt   (revision 
296963)
+++ ext/reflection/tests/ReflectionClass_getProperty_002.phpt   (working copy)
@@ -60,10 +60,10 @@
 
 Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 2 given 
in %s on line 14
 NULL
-Property  does not exist
-Property 1 does not exist
-Property 1.5 does not exist
-Property 1 does not exist
+Property C:: does not exist
+Property C::1 does not exist
+Property C::1.5 does not exist
+Property C::1 does not exist
 
 Warning: ReflectionClass::getProperty() expects parameter 1 to be string, 
array given in %s on line 39
 NULL
Index: ext/reflection/tests/ReflectionClass_getMethod_001.phpt
===================================================================
--- ext/reflection/tests/ReflectionClass_getMethod_001.phpt     (revision 
296963)
+++ ext/reflection/tests/ReflectionClass_getMethod_001.phpt     (working copy)
@@ -65,7 +65,7 @@
   [%u|b%"class"]=>
   %unicode|string%(4) "pubf"
 }
-  --> Check for doesntExist(): Method doesntExist does not exist
+  --> Check for doesntExist(): Method pubf::doesntExist() does not exist
 Reflecting on class subpubf: 
   --> Check for f(): object(ReflectionMethod)#%d (2) {
   [%u|b%"name"]=>
@@ -85,7 +85,7 @@
   [%u|b%"class"]=>
   %unicode|string%(4) "pubf"
 }
-  --> Check for doesntExist(): Method doesntExist does not exist
+  --> Check for doesntExist(): Method subpubf::doesntExist() does not exist
 Reflecting on class protf: 
   --> Check for f(): object(ReflectionMethod)#%d (2) {
   [%u|b%"name"]=>
@@ -105,7 +105,7 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "protf"
 }
-  --> Check for doesntExist(): Method doesntExist does not exist
+  --> Check for doesntExist(): Method protf::doesntExist() does not exist
 Reflecting on class subprotf: 
   --> Check for f(): object(ReflectionMethod)#%d (2) {
   [%u|b%"name"]=>
@@ -125,7 +125,7 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "protf"
 }
-  --> Check for doesntExist(): Method doesntExist does not exist
+  --> Check for doesntExist(): Method subprotf::doesntExist() does not exist
 Reflecting on class privf: 
   --> Check for f(): object(ReflectionMethod)#%d (2) {
   [%u|b%"name"]=>
@@ -145,7 +145,7 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "privf"
 }
-  --> Check for doesntExist(): Method doesntExist does not exist
+  --> Check for doesntExist(): Method privf::doesntExist() does not exist
 Reflecting on class subprivf: 
   --> Check for f(): object(ReflectionMethod)#%d (2) {
   [%u|b%"name"]=>
@@ -165,4 +165,4 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "privf"
 }
-  --> Check for doesntExist(): Method doesntExist does not exist
+  --> Check for doesntExist(): Method subprivf::doesntExist() does not exist
Index: ext/reflection/tests/ReflectionClass_getProperty_003.phpt
===================================================================
--- ext/reflection/tests/ReflectionClass_getProperty_003.phpt   (revision 
296963)
+++ ext/reflection/tests/ReflectionClass_getProperty_003.phpt   (working copy)
@@ -112,7 +112,7 @@
 }
 Cannot access non-public member C::protA
 --- (Reflecting on privA) ---
-Property privA does not exist
+Property C::privA does not exist
 --- (Reflecting on pubB) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -130,7 +130,7 @@
 }
 Cannot access non-public member C::protB
 --- (Reflecting on privB) ---
-Property privB does not exist
+Property C::privB does not exist
 --- (Reflecting on pubC) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -156,7 +156,7 @@
 }
 Cannot access non-public member C::privC
 --- (Reflecting on doesntExist) ---
-Property doesntExist does not exist
+Property C::doesntExist does not exist
 --- (Reflecting on A::pubC) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -214,7 +214,7 @@
 }
 %unicode|string%(9) "pubC in C"
 --- (Reflecting on c::PUBC) ---
-Property PUBC does not exist
+Property C::PUBC does not exist
 --- (Reflecting on C::pubC) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
Index: ext/reflection/tests/ReflectionClass_getMethod_002.phpt
===================================================================
--- ext/reflection/tests/ReflectionClass_getMethod_002.phpt     (revision 
296963)
+++ ext/reflection/tests/ReflectionClass_getMethod_002.phpt     (working copy)
@@ -62,10 +62,10 @@
 
 Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 2 given in 
%s on line 14
 NULL
-Method  does not exist
-Method 1 does not exist
-Method 1.5 does not exist
-Method 1 does not exist
+Method C::() does not exist
+Method C::1() does not exist
+Method C::1.5() does not exist
+Method C::1() does not exist
 
 Warning: ReflectionClass::getMethod() expects parameter 1 to be string, array 
given in %s on line 39
 NULL
Index: ext/reflection/tests/ReflectionClass_getProperty_004.phpt
===================================================================
--- ext/reflection/tests/ReflectionClass_getProperty_004.phpt   (revision 
296963)
+++ ext/reflection/tests/ReflectionClass_getProperty_004.phpt   (working copy)
@@ -112,7 +112,7 @@
 }
 Cannot access non-public member C::protA
 --- (Reflecting on privA) ---
-Property privA does not exist
+Property C::privA does not exist
 --- (Reflecting on pubB) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -130,7 +130,7 @@
 }
 Cannot access non-public member C::protB
 --- (Reflecting on privB) ---
-Property privB does not exist
+Property C::privB does not exist
 --- (Reflecting on pubC) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -156,7 +156,7 @@
 }
 Cannot access non-public member C::privC
 --- (Reflecting on doesntExist) ---
-Property doesntExist does not exist
+Property C::doesntExist does not exist
 --- (Reflecting on A::pubC) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -214,7 +214,7 @@
 }
 %unicode|string%(9) "pubC in C"
 --- (Reflecting on c::PUBC) ---
-Property PUBC does not exist
+Property C::PUBC does not exist
 --- (Reflecting on C::pubC) ---
 object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
Index: ext/reflection/tests/ReflectionClass_getProperty_001.phpt
===================================================================
--- ext/reflection/tests/ReflectionClass_getProperty_001.phpt   (revision 
296963)
+++ ext/reflection/tests/ReflectionClass_getProperty_001.phpt   (working copy)
@@ -72,8 +72,8 @@
   [%u|b%"class"]=>
   %unicode|string%(4) "pubf"
 }
-  --> Check for A: Property A does not exist
-  --> Check for doesntExist: Property doesntExist does not exist
+  --> Check for A: Property pubf::A does not exist
+  --> Check for doesntExist: Property pubf::doesntExist does not exist
 Reflecting on class subpubf: 
   --> Check for s: object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -87,8 +87,8 @@
   [%u|b%"class"]=>
   %unicode|string%(4) "pubf"
 }
-  --> Check for A: Property A does not exist
-  --> Check for doesntExist: Property doesntExist does not exist
+  --> Check for A: Property subpubf::A does not exist
+  --> Check for doesntExist: Property subpubf::doesntExist does not exist
 Reflecting on class protf: 
   --> Check for s: object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -102,8 +102,8 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "protf"
 }
-  --> Check for A: Property A does not exist
-  --> Check for doesntExist: Property doesntExist does not exist
+  --> Check for A: Property protf::A does not exist
+  --> Check for doesntExist: Property protf::doesntExist does not exist
 Reflecting on class subprotf: 
   --> Check for s: object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -117,8 +117,8 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "protf"
 }
-  --> Check for A: Property A does not exist
-  --> Check for doesntExist: Property doesntExist does not exist
+  --> Check for A: Property subprotf::A does not exist
+  --> Check for doesntExist: Property subprotf::doesntExist does not exist
 Reflecting on class privf: 
   --> Check for s: object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -132,8 +132,8 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "privf"
 }
-  --> Check for A: Property A does not exist
-  --> Check for doesntExist: Property doesntExist does not exist
+  --> Check for A: Property privf::A does not exist
+  --> Check for doesntExist: Property privf::doesntExist does not exist
 Reflecting on class subprivf: 
   --> Check for s: object(ReflectionProperty)#%d (2) {
   [%u|b%"name"]=>
@@ -141,6 +141,6 @@
   [%u|b%"class"]=>
   %unicode|string%(5) "privf"
 }
-  --> Check for a: Property a does not exist
-  --> Check for A: Property A does not exist
-  --> Check for doesntExist: Property doesntExist does not exist
+  --> Check for a: Property subprivf::a does not exist
+  --> Check for A: Property subprivf::A does not exist
+  --> Check for doesntExist: Property subprivf::doesntExist does not exist
Index: ext/reflection/tests/bug49719.phpt
===================================================================
--- ext/reflection/tests/bug49719.phpt  (revision 296963)
+++ ext/reflection/tests/bug49719.phpt  (working copy)
@@ -40,5 +40,5 @@
 bool(false)
 bool(false)
 bool(false)
-%string|unicode%(25) "Property a does not exist"
+%string|unicode%(28) "Property B::a does not exist"
 int(2)
Index: ext/reflection/php_reflection.c
===================================================================
--- ext/reflection/php_reflection.c     (revision 296963)
+++ ext/reflection/php_reflection.c     (working copy)
@@ -3425,7 +3425,7 @@
        } else {
                efree(lc_name);
                zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
-                               "Method %s does not exist", name);
+                               "Method %s::%s() does not exist", ce->name, 
name);
                return;
        }
 }
@@ -3602,7 +3602,7 @@
                }               
        }
        zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
-                       "Property %s does not exist", name);
+                       "Property %s::%s does not exist", ce->name, name);
 }
 /* }}} */
 
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to