com php-src: Add tests for indirect calls to methods on non-objects http://news.php.net/php.internals/73823:
Zend/tests/methods-on-non-objects-call-user-func.phpt Zend/tests/methods-on-non-objects-usort.phpt
| From: | Tjerk Anne Meesters | Date: | Mon, 28 Apr 2014 19:44:24 +0000 |
| Subject: | com php-src: Add tests for indirect calls to methods on non-objects http://news.php.net/php.internals/73823: Zend/tests/methods-on-non-objects-call-user-func.phpt Zend/tests/methods-on-non-objects-usort.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82148@lists.php.net to get a copy of this message | ||
Commit: da1db5e688c46a044bc0745c86cc34cc4e9ab808
Author: Timm Friebe <thekid@thekid.de> Mon, 28 Apr 2014 21:44:24 +0200
Parents: a86e7621666bce5dcf5ac3304b2384b254319025
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=da1db5e688c46a044bc0745c86cc34cc4e9ab808
Log:
Add tests for indirect calls to methods on non-objects
http://news.php.net/php.internals/73823
Changed paths:
A Zend/tests/methods-on-non-objects-call-user-func.phpt
A Zend/tests/methods-on-non-objects-usort.phpt
Diff:
diff --git a/Zend/tests/methods-on-non-objects-call-user-func.phpt
b/Zend/tests/methods-on-non-objects-call-user-func.phpt
new file mode 100644
index 0000000..f76b7d4
--- /dev/null
+++ b/Zend/tests/methods-on-non-objects-call-user-func.phpt
@@ -0,0 +1,13 @@
+--TEST--
+call_user_func() in combination with "Call to a member function method() on a non-object"
+--FILE--
+<?php
+$comparator= null;
+var_dump(call_user_func([$comparator, 'compare'], 1, 2));
+echo "Alive\n";
+?>
+--EXPECTF--
+Warning: call_user_func() expects parameter 1 to be a valid callback, first array member is not a
valid class name or object in %s on line %d
+NULL
+Alive
+
diff --git a/Zend/tests/methods-on-non-objects-usort.phpt
b/Zend/tests/methods-on-non-objects-usort.phpt
new file mode 100644
index 0000000..df702d3
--- /dev/null
+++ b/Zend/tests/methods-on-non-objects-usort.phpt
@@ -0,0 +1,43 @@
+--TEST--
+usort() in combination with "Call to a member function method() on a non-object"
+--FILE--
+<?php
+set_error_handler(function($code, $message) {
+ var_dump($code, $message);
+});
+
+$comparator= null;
+$list= [1, 4, 2, 3, -1];
+usort($list, function($a, $b) use ($comparator) {
+ return $comparator->compare($a, $b);
+});
+var_dump($list);
+echo "Alive\n";
+?>
+--EXPECTF--
+int(4096)
+string(51) "Call to a member function compare() on a non-object"
+int(4096)
+string(51) "Call to a member function compare() on a non-object"
+int(4096)
+string(51) "Call to a member function compare() on a non-object"
+int(4096)
+string(51) "Call to a member function compare() on a non-object"
+int(4096)
+string(51) "Call to a member function compare() on a non-object"
+int(4096)
+string(51) "Call to a member function compare() on a non-object"
+array(5) {
+ [0]=>
+ int(-1)
+ [1]=>
+ int(3)
+ [2]=>
+ int(2)
+ [3]=>
+ int(4)
+ [4]=>
+ int(1)
+}
+Alive
+