com php-src: Add example how framework code could convert E_RECOVERABLE -> exceptions: Zend/tests/methods-on- non-objects-throw.phpt
| From: | Tjerk Anne Meesters | Date: | Sat, 19 Apr 2014 13:32:16 +0000 |
| Subject: | com php-src: Add example how framework code could convert E_RECOVERABLE -> exceptions: Zend/tests/methods-on- non-objects-throw.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82152@lists.php.net to get a copy of this message | ||
Commit: 51a5e184335373e0bcfd6c65fdb22c6908768a83
Author: Timm Friebe <thekid@thekid.de> Sat, 19 Apr 2014 15:32:16 +0200
Parents: a6f7f58a87a09a45c6432c5224a633d6721676f0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=51a5e184335373e0bcfd6c65fdb22c6908768a83
Log:
Add example how framework code could convert E_RECOVERABLE -> exceptions
Changed paths:
A Zend/tests/methods-on-non-objects-throw.phpt
Diff:
diff --git a/Zend/tests/methods-on-non-objects-throw.phpt
b/Zend/tests/methods-on-non-objects-throw.phpt
new file mode 100644
index 0000000..7bbbbf6
--- /dev/null
+++ b/Zend/tests/methods-on-non-objects-throw.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Convert errors to exceptions from method calls on non-objects raise recoverable errors
+--FILE--
+<?php
+set_error_handler(function($code, $message) {
+ if (0 === strncmp('Call', $message, 4)) {
+ throw new BadMethodCallException($message);
+ } else if (0 === strncmp('Argument', $message, 8)) {
+ throw new InvalidArgumentException($message);
+ } else {
+ trigger_error($message, E_USER_ERROR);
+ }
+}, E_RECOVERABLE_ERROR);
+
+$x= null;
+try {
+ $x->method();
+} catch (BadMethodCallException $e) {
+ echo "Caught expected ", $e->getMessage(), "!\n";
+}
+echo "Alive\n";
+?>
+--EXPECTF--
+Caught expected Call to a member function method() on a non-object!
+Alive