]> granicus.if.org Git - php/commitdiff
Fixed bug #77772
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Mar 2019 11:39:27 +0000 (12:39 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Mar 2019 11:39:27 +0000 (12:39 +0100)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug77772.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e35e2d405ec7939daf65452435cc0479b8ebd1ad..dbce1af2995dba7707a5035b4f7c61c56e00e32c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2019, PHP 7.2.18
 
+- Reflection:
+  . Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
+
 04 Apr 2019, PHP 7.2.17
 
 - Core:
index f1096fbe817b0413895286a603375570e78fb553..80e508c1750b214a525d015c2925de1cced1302b 100644 (file)
@@ -4246,15 +4246,14 @@ ZEND_METHOD(reflection_class, getMethods)
        reflection_object *intern;
        zend_class_entry *ce;
        zend_long filter = 0;
-       int argc = ZEND_NUM_ARGS();
+       zend_bool filter_is_null = 1;
 
        METHOD_NOTSTATIC(reflection_class_ptr);
-       if (argc) {
-               if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) {
-                       return;
-               }
-       } else {
-               /* No parameters given, default to "return all" */
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) {
+               return;
+       }
+
+       if (filter_is_null) {
                filter = ZEND_ACC_PPP_MASK | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL | ZEND_ACC_STATIC;
        }
 
@@ -4442,15 +4441,14 @@ ZEND_METHOD(reflection_class, getProperties)
        reflection_object *intern;
        zend_class_entry *ce;
        zend_long filter = 0;
-       int argc = ZEND_NUM_ARGS();
+       zend_bool filter_is_null = 1;
 
        METHOD_NOTSTATIC(reflection_class_ptr);
-       if (argc) {
-               if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) {
-                       return;
-               }
-       } else {
-               /* No parameters given, default to "return all" */
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) {
+               return;
+       }
+       
+       if (filter_is_null) {
                filter = ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC;
        }
 
diff --git a/ext/reflection/tests/bug77772.phpt b/ext/reflection/tests/bug77772.phpt
new file mode 100644 (file)
index 0000000..0769621
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #77772: ReflectionClass::getMethods(null) doesn't work
+--FILE--
+<?php
+
+class Test {
+    public $prop;
+    public function method() {}
+}
+
+$rc = new ReflectionClass(Test::class);
+foreach ($rc->getMethods(null) as $method) {
+    var_dump($method->getName());
+}
+foreach ($rc->getProperties(null) as $prop) {
+    var_dump($prop->getName());
+}
+
+?>
+--EXPECT--
+string(6) "method"
+string(4) "prop"