]> granicus.if.org Git - php/commitdiff
preserve the orig class name when extending the ErrorException
authorAnatol Belski <ab@php.net>
Wed, 17 Jun 2015 22:30:16 +0000 (00:30 +0200)
committerAnatol Belski <ab@php.net>
Wed, 17 Jun 2015 22:30:16 +0000 (00:30 +0200)
Zend/tests/exception_020.phpt [new file with mode: 0644]
Zend/zend_exceptions.c

diff --git a/Zend/tests/exception_020.phpt b/Zend/tests/exception_020.phpt
new file mode 100644 (file)
index 0000000..72a6033
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Testing throw exception doesn't crash with wrong params, variant 2
+--FILE--
+<?php
+
+class MyErrorException extends ErrorException{}
+throw new MyErrorException(new stdClass);
+
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Wrong parameters for MyErrorException([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Throwable $previous = NULL]]]]]]) in %sexception_020.php:%d
+Stack trace:
+#0 %sexception_020.php(%d): ErrorException->__construct(Object(stdClass))
+#1 {main}
+  thrown in %sexception_020.php on line %d
index 0d9506445ee04036f5bd23a33526f11b4122fecd..d6d4fc735a076bdc22a3e7f65540e62d5049f5e5 100644 (file)
@@ -282,7 +282,14 @@ ZEND_METHOD(error_exception, __construct)
        size_t message_len, filename_len;
 
        if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, zend_ce_throwable) == FAILURE) {
-               zend_error(E_EXCEPTION | E_ERROR, "Wrong parameters for ErrorException([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Throwable $previous = NULL]]]]]])");
+               zend_class_entry *ce;
+
+               if (execute_data->called_scope) {
+                       ce = execute_data->called_scope;
+               } else {
+                       ce = error_exception_ce;
+               }
+               zend_error(E_EXCEPTION | E_ERROR, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Throwable $previous = NULL]]]]]])", ce->name->val);
                return;
        }