[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] com php-src: Fix fetching default value of internal function with userland arginfo: =?UTF-
From:       Nikita Popov <nikic () php ! net>
Date:       2020-08-31 12:03:54
Message-ID: php-mail-038f706fe7aacb78f495169d1fc559031297449822 () git ! php ! net
[Download RAW message or body]

Commit:    b4196ae9dfb345f0fd52084d5574d60c49139dc7
Author:    Nikita Popov <nikita.ppv@gmail.com>         Mon, 31 Aug 2020 14:02:35 \
                +0200
Parents:   bef20d47afbb1afae6217fd914172313ad2236dd
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=b4196ae9dfb345f0fd52084d5574d60c49139dc7


Log:
Fix fetching default value of internal function with userland arginfo

"Fix" in the sense of "not crash". We aren't able to actually
display the default value for this case, as there's no way to
fetch the relevant information right now.

Changed paths:
  M  ext/reflection/php_reflection.c
  A  ext/reflection/tests/default_value_internal_userland_arginfo.phpt


Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index a24d72c747d..016851e9e54 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -667,7 +667,10 @@ static void _parameter_string(smart_str *str, zend_function \
*fptr, struct _zend_  if (!required) {
 		if (fptr->type == ZEND_INTERNAL_FUNCTION) {
 			smart_str_appends(str, " = ");
-			if (((zend_internal_arg_info*)arg_info)->default_value) {
+			/* TODO: We don't have a way to fetch the default value for an internal function
+			 * with userland arg info. */
+			if (has_internal_arg_info(fptr)
+					&& ((zend_internal_arg_info*)arg_info)->default_value) {
 				smart_str_appends(str, ((zend_internal_arg_info*)arg_info)->default_value);
 			} else {
 				smart_str_appends(str, "<default>");
diff --git a/ext/reflection/tests/default_value_internal_userland_arginfo.phpt \
b/ext/reflection/tests/default_value_internal_userland_arginfo.phpt new file mode \
100644 index 00000000000..d2b0589cd19
--- /dev/null
+++ b/ext/reflection/tests/default_value_internal_userland_arginfo.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Fetching default value of an internal trampoline function with userland arginfo
+--FILE--
+<?php
+$closure = function ($b = 0) {};
+$ro = new ReflectionObject($closure);
+$rm = $ro->getMethod('__invoke');
+echo $rm, "\n";
+?>
+--EXPECT--
+Method [ <internal> public method __invoke ] {
+
+  - Parameters [1] {
+    Parameter #0 [ <optional> $b = <default> ]
+  }
+}


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic