com php-src: Fixed bug #73118: NEWS ext/standard/tests/general _functions/is_callable_anon.phpt ext/standard/tests/g eneral_functions/is_callable_variation1.phpt ext/st andard/type.c

[email protected] (Nikita Popov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    7e5cf2aa194a45470efe1fbe590ebff74034df14
Author:    Adam Saponara <[email protected]>         Fri, 10 Feb 2017 23:58:25 -0500
Committer: Nikita Popov <[email protected]>      Sun, 12 Feb 2017 00:14:59 +0100
Parents:   9814be4bc28892d1e0a5dc875fef0b4bde455d23
Branches:  PHP-7.0 PHP-7.1 master

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

Log:
Fixed bug #73118

Bugs:
https://bugs.php.net/73118

Changed paths:
  M  NEWS
  A  ext/standard/tests/general_functions/is_callable_anon.phpt
  M  ext/standard/tests/general_functions/is_callable_variation1.phpt
  M  ext/standard/type.c


Diff:
diff --git a/NEWS b/NEWS
index 24f5d0f..f78594b 100644
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,8 @@ PHP                                                                        NEWS
 - Standard:
   . Fixed bug #74005 (mail.add_x_header causes RFC-breaking lone line feed).
     (Anatol)
+  . Fixed bug #73118 (is_callable callable name reports misleading value for
+    anonymous classes). (Adam Saponara)
 
 
 16 Feb 2017 PHP 7.0.16
diff --git a/ext/standard/tests/general_functions/is_callable_anon.phpt b/ext/standard/tests/general_functions/is_callable_anon.phpt
new file mode 100644
index 0000000..635f2a0
--- /dev/null
+++ b/ext/standard/tests/general_functions/is_callable_anon.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Test is_callable() function : usage variations - anonymous class method
+--FILE--
+<?php
+
+new class {
+    function __construct() {
+        $fname = null;
+        if (is_callable([$this, 'f'], false, $fname)) {
+            call_user_func($fname);
+        } else {
+            echo "dang\n";
+        }
+    }
+    function f() {
+        echo "nice\n";
+    }
+};
+
+?>
+--EXPECT--
+nice
diff --git a/ext/standard/tests/general_functions/is_callable_variation1.phpt b/ext/standard/tests/general_functions/is_callable_variation1.phpt
index cfc14bb..0a4609b 100644
--- a/ext/standard/tests/general_functions/is_callable_variation1.phpt
+++ b/ext/standard/tests/general_functions/is_callable_variation1.phpt
@@ -21,10 +21,10 @@ function check_iscallable( $functions ) {
     var_dump( is_callable($func) );  //given only $var argument
     var_dump( is_callable($func, TRUE) );  //given $var and $syntax argument
     var_dump( is_callable($func, TRUE, $callable_name) );
-    echo $callable_name, "\n";
+    echo json_encode($callable_name) . "\n";
     var_dump( is_callable($func, FALSE) );  //given $var and $syntax argument
     var_dump( is_callable($func, FALSE, $callable_name) );
-    echo $callable_name, "\n";
+    echo json_encode($callable_name) . "\n";
     $counter++;
   }
 }
@@ -65,144 +65,144 @@ check_iscallable($undef_functions);
 bool(false)
 bool(true)
 bool(true)
-
+""
 bool(false)
 bool(false)
-
+""
 -- Iteration  2 --
 bool(false)
 bool(true)
 bool(true)
-
+""
 bool(false)
 bool(false)
-
+""
 -- Iteration  3 --
 bool(false)
 bool(true)
 bool(true)
- 
+" "
 bool(false)
 bool(false)
- 
+" "
 -- Iteration  4 --
 bool(false)
 bool(true)
 bool(true)
- 
+" "
 bool(false)
 bool(false)
- 
+" "
 -- Iteration  5 --
 bool(false)
 bool(true)
 bool(true)
-12356
+"12356"
 bool(false)
 bool(false)
-12356
+"12356"
 -- Iteration  6 --
 bool(false)
 bool(true)
 bool(true)
-
+"\u0000"
 bool(false)
 bool(false)
-
+"\u0000"
 -- Iteration  7 --
 bool(false)
 bool(true)
 bool(true)
-\0
+"\\0"
 bool(false)
 bool(false)
-\0
+"\\0"
 -- Iteration  8 --
 bool(false)
 bool(true)
 bool(true)
-hello world
+"hello world"
 bool(false)
 bool(false)
-hello world
+"hello world"
 -- Iteration  9 --
 bool(false)
 bool(true)
 bool(true)
-hello world
+"hello world"
 bool(false)
 bool(false)
-hello world
+"hello world"
 -- Iteration  10 --
 bool(false)
 bool(true)
 bool(true)
-welcome
+"welcome\u0000"
 bool(false)
 bool(false)
-welcome
+"welcome\u0000"
 -- Iteration  11 --
 bool(false)
 bool(true)
 bool(true)
-welcome\0
+"welcome\\0"
 bool(false)
 bool(false)
-welcome\0
+"welcome\\0"
 -- Iteration  12 --
 bool(false)
 bool(true)
 bool(true)
-==%%%***$$$@@@!!
+"==%%%***$$$@@@!!"
 bool(false)
 bool(false)
-==%%%***$$$@@@!!
+"==%%%***$$$@@@!!"
 -- Iteration  13 --
 bool(false)
 bool(true)
 bool(true)
-false
+"false"
 bool(false)
 bool(false)
-false
+"false"
 -- Iteration  14 --
 bool(false)
 bool(true)
 bool(true)
-8
+"8"
 bool(false)
 bool(false)
-8
+"8"
 -- Iteration  15 --
 bool(false)
 bool(true)
 bool(true)
-\t
+"\\t"
 bool(false)
 bool(false)
-\t
+"\\t"
 -- Iteration  16 --
 bool(false)
 bool(true)
 bool(true)
-\007
+"\\007"
 bool(false)
 bool(false)
-\007
+"\\007"
 -- Iteration  17 --
 bool(false)
 bool(true)
 bool(true)
-123
+"123"
 bool(false)
 bool(false)
-123
+"123"
 -- Iteration  18 --
 bool(false)
 bool(true)
 bool(true)
-echo()
+"echo()"
 bool(false)
 bool(false)
-echo()
-===DONE===
\ No newline at end of file
+"echo()"
+===DONE===
diff --git a/ext/standard/type.c b/ext/standard/type.c
index 033eca4..a9686a2 100644
--- a/ext/standard/type.c
+++ b/ext/standard/type.c
@@ -384,13 +384,7 @@ PHP_FUNCTION(is_callable)
 	if (ZEND_NUM_ARGS() > 2) {
 		retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, &error);
 		zval_dtor(callable_name);
-		//??? is it necessary to be consistent with old PHP ("\0" support)
-		if (UNEXPECTED(ZSTR_LEN(name)) != strlen(ZSTR_VAL(name))) {
-			ZVAL_STRINGL(callable_name, ZSTR_VAL(name), strlen(ZSTR_VAL(name)));
-			zend_string_release(name);
-		} else {
-			ZVAL_STR(callable_name, name);
-		}
+		ZVAL_STR(callable_name, name);
 	} else {
 		retval = zend_is_callable_ex(var, NULL, check_flags, NULL, NULL, &error);
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.