]> granicus.if.org Git - php/commitdiff
Fixed bug #54043
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 23 Dec 2017 12:34:17 +0000 (13:34 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 23 Dec 2017 12:35:08 +0000 (13:35 +0100)
NEWS
UPGRADING
Zend/tests/bug54043.phpt [new file with mode: 0644]
main/main.c

diff --git a/NEWS b/NEWS
index 4a6447b89f5c4b245dd94942af735a09159106ce..3757f65384b7e2da7f9cb175cd3c6a9cce70b70b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,11 +25,13 @@ PHP                                                                        NEWS
     (pmmaga)
   . Fixed bug #75677 (Clang ignores fastcall calling convention on variadic
     function). (Li-Wen Hsu)
+  . Fixed bug #54043 (Remove inconsitency of internal exceptions and user
+    defined exceptions). (Nikita)
 
 - BCMath:
   . Fixed bug #66364 (BCMath bcmul ignores scale parameter). (cmb)
-       . Implemented request #67855 (No way to get current scale in use). (Chris
-         Wright, cmb)
+  . Implemented request #67855 (No way to get current scale in use). (Chris
+    Wright, cmb)
   . Fixed bug #75164 (split_bc_num() is pointless). (cmb)
   . Fixed bug #75169 (BCMath errors/warnings bypass PHP's error handling). (cmb)
 
index 1baa83f19aca66ade441d516b681d78d8ca43294..85d74a02c5fb88e572315254d8067eae84248101 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -24,6 +24,10 @@ Core:
     some old options removed. This is now written in PHP and has no external 
        dependencies.
   . Support for BeOS has been dropped.
+  . Exceptions thrown due to automatic conversion of warnings into exceptions
+    in EH_THROW mode (e.g. some DateTime exceptions) no longer populate
+    error_get_last() state. As such, they now work the same way as manually
+    thrown exceptions.
 
 BCMath:
   . All warnings thrown by BCMath functions are now using PHP's error handling.
diff --git a/Zend/tests/bug54043.phpt b/Zend/tests/bug54043.phpt
new file mode 100644 (file)
index 0000000..a8bbcf6
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #54043: Remove inconsitency of internal exceptions and user defined exceptions
+--FILE--
+<?php
+
+$time = '9999-11-33';  // obviously invalid ;-)
+$timeZone = new DateTimeZone('UTC');
+
+try {
+    $dateTime = new DateTime($time, $timeZone);
+} catch (Exception $e) {
+    var_dump($e->getMessage());
+}
+
+var_dump(error_get_last());
+
+?>
+--EXPECT--
+string(105) "DateTime::__construct(): Failed to parse time string (9999-11-33) at position 9 (3): Unexpected character"
+NULL
index 7dd65253ed3d30f1d31e26496227208787dd1ba5..24e096b242d22ac538dc5ec036d21eb9e89f1bc1 100644 (file)
@@ -1053,27 +1053,6 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u
                display = 1;
        }
 
-       /* store the error if it has changed */
-       if (display) {
-               if (PG(last_error_message)) {
-                       char *s = PG(last_error_message);
-                       PG(last_error_message) = NULL;
-                       free(s);
-               }
-               if (PG(last_error_file)) {
-                       char *s = PG(last_error_file);
-                       PG(last_error_file) = NULL;
-                       free(s);
-               }
-               if (!error_filename) {
-                       error_filename = "Unknown";
-               }
-               PG(last_error_type) = type;
-               PG(last_error_message) = strdup(buffer);
-               PG(last_error_file) = strdup(error_filename);
-               PG(last_error_lineno) = error_lineno;
-       }
-
        /* according to error handling mode, throw exception or show it */
        if (EG(error_handling) == EH_THROW) {
                switch (type) {
@@ -1105,6 +1084,27 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u
                }
        }
 
+       /* store the error if it has changed */
+       if (display) {
+               if (PG(last_error_message)) {
+                       char *s = PG(last_error_message);
+                       PG(last_error_message) = NULL;
+                       free(s);
+               }
+               if (PG(last_error_file)) {
+                       char *s = PG(last_error_file);
+                       PG(last_error_file) = NULL;
+                       free(s);
+               }
+               if (!error_filename) {
+                       error_filename = "Unknown";
+               }
+               PG(last_error_type) = type;
+               PG(last_error_message) = strdup(buffer);
+               PG(last_error_file) = strdup(error_filename);
+               PG(last_error_lineno) = error_lineno;
+       }
+
        /* display/log the error if necessary */
        if (display && (EG(error_reporting) & type || (type & E_CORE))
                && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {