]> granicus.if.org Git - php/commitdiff
Ensure Exception::getFile/getLine return type is correct
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 28 May 2020 12:19:47 +0000 (14:19 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 28 May 2020 12:19:47 +0000 (14:19 +0200)
These return an untyped protected property, so we can't rely on
the type being correct.

Also add return types to the interface -- normally this would be
a no-go, but Throwable is a special interface that can only
be implemented internally, so we control all implementations.

Zend/zend_exceptions.c
Zend/zend_exceptions.stub.php
Zend/zend_exceptions_arginfo.h

index 6262685c47d6fe20f2a04a611c727563394b2ef5..a2bdbdad746fbf092d8beaefe990adabf2d83bd0 100644 (file)
@@ -380,8 +380,7 @@ ZEND_METHOD(Exception, getFile)
        ZEND_PARSE_PARAMETERS_NONE();
 
        prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_FILE);
-       ZVAL_DEREF(prop);
-       ZVAL_COPY(return_value, prop);
+       RETURN_STR(zval_get_string(prop));
 }
 /* }}} */
 
@@ -394,8 +393,7 @@ ZEND_METHOD(Exception, getLine)
        ZEND_PARSE_PARAMETERS_NONE();
 
        prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_LINE);
-       ZVAL_DEREF(prop);
-       ZVAL_COPY(return_value, prop);
+       RETURN_LONG(zval_get_long(prop));
 }
 /* }}} */
 
index c467f36ecb584692b27e9f5d0e4321e0d80a7002..9cf55fd38404ecb5c01ec61fe4b50f833ea24e95 100644 (file)
@@ -4,26 +4,20 @@
 
 interface Throwable extends Stringable
 {
-    /** @return string */
-    public function getMessage();
+    public function getMessage(): string;
 
     /** @return int */
     public function getCode();
 
-    /** @return string */
-    public function getFile();
+    public function getFile(): string;
 
-    /** @return int */
-    public function getLine();
+    public function getLine(): int;
 
-    /** @return array */
-    public function getTrace();
+    public function getTrace(): array;
 
-    /** @return ?Throwable */
-    public function getPrevious();
+    public function getPrevious(): ?Throwable;
 
-    /** @return string */
-    public function getTraceAsString();
+    public function getTraceAsString(): string;
 }
 
 class Exception implements Throwable
index 3f8ceb833b11a48b071596132a74446d226abcd3..db114fbeaad2fb6cd8f068081cd2e49279e9f769 100644 (file)
@@ -1,21 +1,25 @@
 /* This is a generated file, edit the .stub.php file instead. */
 
-ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_Throwable_getCode arginfo_class_Throwable_getMessage
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Throwable_getCode, 0, 0, 0)
+ZEND_END_ARG_INFO()
 
 #define arginfo_class_Throwable_getFile arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Throwable_getLine arginfo_class_Throwable_getMessage
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getLine, 0, 0, IS_LONG, 0)
+ZEND_END_ARG_INFO()
 
-#define arginfo_class_Throwable_getTrace arginfo_class_Throwable_getMessage
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getTrace, 0, 0, IS_ARRAY, 0)
+ZEND_END_ARG_INFO()
 
-#define arginfo_class_Throwable_getPrevious arginfo_class_Throwable_getMessage
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Throwable_getPrevious, 0, 0, Throwable, 1)
+ZEND_END_ARG_INFO()
 
 #define arginfo_class_Throwable_getTraceAsString arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Exception___clone arginfo_class_Throwable_getMessage
+#define arginfo_class_Exception___clone arginfo_class_Throwable_getCode
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Exception___construct, 0, 0, 0)
        ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
@@ -23,27 +27,23 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Exception___construct, 0, 0, 0)
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, previous, Throwable, 1, "null")
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_Exception___wakeup arginfo_class_Throwable_getMessage
+#define arginfo_class_Exception___wakeup arginfo_class_Throwable_getCode
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getMessage, 0, 0, IS_STRING, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Exception_getMessage arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Exception_getCode arginfo_class_Throwable_getMessage
+#define arginfo_class_Exception_getCode arginfo_class_Throwable_getCode
 
-#define arginfo_class_Exception_getFile arginfo_class_Exception_getMessage
+#define arginfo_class_Exception_getFile arginfo_class_Throwable_getMessage
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getLine, 0, 0, IS_LONG, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Exception_getLine arginfo_class_Throwable_getLine
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getTrace, 0, 0, IS_ARRAY, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Exception_getTrace arginfo_class_Throwable_getTrace
 
-ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Exception_getPrevious, 0, 0, Throwable, 1)
-ZEND_END_ARG_INFO()
+#define arginfo_class_Exception_getPrevious arginfo_class_Throwable_getPrevious
 
-#define arginfo_class_Exception_getTraceAsString arginfo_class_Exception_getMessage
+#define arginfo_class_Exception_getTraceAsString arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Exception___toString arginfo_class_Exception_getMessage
+#define arginfo_class_Exception___toString arginfo_class_Throwable_getMessage
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ErrorException___construct, 0, 0, 0)
        ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
@@ -54,29 +54,29 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ErrorException___construct, 0, 0, 0)
        ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, previous, Throwable, 1, "null")
 ZEND_END_ARG_INFO()
 
-#define arginfo_class_ErrorException_getSeverity arginfo_class_Exception_getLine
+#define arginfo_class_ErrorException_getSeverity arginfo_class_Throwable_getLine
 
-#define arginfo_class_Error___clone arginfo_class_Throwable_getMessage
+#define arginfo_class_Error___clone arginfo_class_Throwable_getCode
 
 #define arginfo_class_Error___construct arginfo_class_Exception___construct
 
-#define arginfo_class_Error___wakeup arginfo_class_Throwable_getMessage
+#define arginfo_class_Error___wakeup arginfo_class_Throwable_getCode
 
-#define arginfo_class_Error_getMessage arginfo_class_Exception_getMessage
+#define arginfo_class_Error_getMessage arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Error_getCode arginfo_class_Throwable_getMessage
+#define arginfo_class_Error_getCode arginfo_class_Throwable_getCode
 
-#define arginfo_class_Error_getFile arginfo_class_Exception_getMessage
+#define arginfo_class_Error_getFile arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Error_getLine arginfo_class_Exception_getLine
+#define arginfo_class_Error_getLine arginfo_class_Throwable_getLine
 
-#define arginfo_class_Error_getTrace arginfo_class_Exception_getTrace
+#define arginfo_class_Error_getTrace arginfo_class_Throwable_getTrace
 
-#define arginfo_class_Error_getPrevious arginfo_class_Exception_getPrevious
+#define arginfo_class_Error_getPrevious arginfo_class_Throwable_getPrevious
 
-#define arginfo_class_Error_getTraceAsString arginfo_class_Exception_getMessage
+#define arginfo_class_Error_getTraceAsString arginfo_class_Throwable_getMessage
 
-#define arginfo_class_Error___toString arginfo_class_Exception_getMessage
+#define arginfo_class_Error___toString arginfo_class_Throwable_getMessage
 
 
 ZEND_METHOD(Exception, __clone);