Skip to content

Commit 70b2aa7

Browse files
committed
Ensure Exception::getFile/getLine return type is correct
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.
1 parent d579e18 commit 70b2aa7

File tree

3 files changed

+38
-46
lines changed

3 files changed

+38
-46
lines changed

Zend/zend_exceptions.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ ZEND_METHOD(Exception, getFile)
380380
ZEND_PARSE_PARAMETERS_NONE();
381381

382382
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_FILE);
383-
ZVAL_DEREF(prop);
384-
ZVAL_COPY(return_value, prop);
383+
RETURN_STR(zval_get_string(prop));
385384
}
386385
/* }}} */
387386

@@ -394,8 +393,7 @@ ZEND_METHOD(Exception, getLine)
394393
ZEND_PARSE_PARAMETERS_NONE();
395394

396395
prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_LINE);
397-
ZVAL_DEREF(prop);
398-
ZVAL_COPY(return_value, prop);
396+
RETURN_LONG(zval_get_long(prop));
399397
}
400398
/* }}} */
401399

Zend/zend_exceptions.stub.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,20 @@
44

55
interface Throwable extends Stringable
66
{
7-
/** @return string */
8-
public function getMessage();
7+
public function getMessage(): string;
98

109
/** @return int */
1110
public function getCode();
1211

13-
/** @return string */
14-
public function getFile();
12+
public function getFile(): string;
1513

16-
/** @return int */
17-
public function getLine();
14+
public function getLine(): int;
1815

19-
/** @return array */
20-
public function getTrace();
16+
public function getTrace(): array;
2117

22-
/** @return ?Throwable */
23-
public function getPrevious();
18+
public function getPrevious(): ?Throwable;
2419

25-
/** @return string */
26-
public function getTraceAsString();
20+
public function getTraceAsString(): string;
2721
}
2822

2923
class Exception implements Throwable

Zend/zend_exceptions_arginfo.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
/* This is a generated file, edit the .stub.php file instead. */
22

3-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, 0)
3+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
44
ZEND_END_ARG_INFO()
55

6-
#define arginfo_class_Throwable_getCode arginfo_class_Throwable_getMessage
6+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Throwable_getCode, 0, 0, 0)
7+
ZEND_END_ARG_INFO()
78

89
#define arginfo_class_Throwable_getFile arginfo_class_Throwable_getMessage
910

10-
#define arginfo_class_Throwable_getLine arginfo_class_Throwable_getMessage
11+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getLine, 0, 0, IS_LONG, 0)
12+
ZEND_END_ARG_INFO()
1113

12-
#define arginfo_class_Throwable_getTrace arginfo_class_Throwable_getMessage
14+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getTrace, 0, 0, IS_ARRAY, 0)
15+
ZEND_END_ARG_INFO()
1316

14-
#define arginfo_class_Throwable_getPrevious arginfo_class_Throwable_getMessage
17+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Throwable_getPrevious, 0, 0, Throwable, 1)
18+
ZEND_END_ARG_INFO()
1519

1620
#define arginfo_class_Throwable_getTraceAsString arginfo_class_Throwable_getMessage
1721

18-
#define arginfo_class_Exception___clone arginfo_class_Throwable_getMessage
22+
#define arginfo_class_Exception___clone arginfo_class_Throwable_getCode
1923

2024
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Exception___construct, 0, 0, 0)
2125
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
2226
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_LONG, 0, "0")
2327
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, previous, Throwable, 1, "null")
2428
ZEND_END_ARG_INFO()
2529

26-
#define arginfo_class_Exception___wakeup arginfo_class_Throwable_getMessage
30+
#define arginfo_class_Exception___wakeup arginfo_class_Throwable_getCode
2731

28-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getMessage, 0, 0, IS_STRING, 0)
29-
ZEND_END_ARG_INFO()
32+
#define arginfo_class_Exception_getMessage arginfo_class_Throwable_getMessage
3033

31-
#define arginfo_class_Exception_getCode arginfo_class_Throwable_getMessage
34+
#define arginfo_class_Exception_getCode arginfo_class_Throwable_getCode
3235

33-
#define arginfo_class_Exception_getFile arginfo_class_Exception_getMessage
36+
#define arginfo_class_Exception_getFile arginfo_class_Throwable_getMessage
3437

35-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getLine, 0, 0, IS_LONG, 0)
36-
ZEND_END_ARG_INFO()
38+
#define arginfo_class_Exception_getLine arginfo_class_Throwable_getLine
3739

38-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getTrace, 0, 0, IS_ARRAY, 0)
39-
ZEND_END_ARG_INFO()
40+
#define arginfo_class_Exception_getTrace arginfo_class_Throwable_getTrace
4041

41-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Exception_getPrevious, 0, 0, Throwable, 1)
42-
ZEND_END_ARG_INFO()
42+
#define arginfo_class_Exception_getPrevious arginfo_class_Throwable_getPrevious
4343

44-
#define arginfo_class_Exception_getTraceAsString arginfo_class_Exception_getMessage
44+
#define arginfo_class_Exception_getTraceAsString arginfo_class_Throwable_getMessage
4545

46-
#define arginfo_class_Exception___toString arginfo_class_Exception_getMessage
46+
#define arginfo_class_Exception___toString arginfo_class_Throwable_getMessage
4747

4848
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ErrorException___construct, 0, 0, 0)
4949
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)
5454
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, previous, Throwable, 1, "null")
5555
ZEND_END_ARG_INFO()
5656

57-
#define arginfo_class_ErrorException_getSeverity arginfo_class_Exception_getLine
57+
#define arginfo_class_ErrorException_getSeverity arginfo_class_Throwable_getLine
5858

59-
#define arginfo_class_Error___clone arginfo_class_Throwable_getMessage
59+
#define arginfo_class_Error___clone arginfo_class_Throwable_getCode
6060

6161
#define arginfo_class_Error___construct arginfo_class_Exception___construct
6262

63-
#define arginfo_class_Error___wakeup arginfo_class_Throwable_getMessage
63+
#define arginfo_class_Error___wakeup arginfo_class_Throwable_getCode
6464

65-
#define arginfo_class_Error_getMessage arginfo_class_Exception_getMessage
65+
#define arginfo_class_Error_getMessage arginfo_class_Throwable_getMessage
6666

67-
#define arginfo_class_Error_getCode arginfo_class_Throwable_getMessage
67+
#define arginfo_class_Error_getCode arginfo_class_Throwable_getCode
6868

69-
#define arginfo_class_Error_getFile arginfo_class_Exception_getMessage
69+
#define arginfo_class_Error_getFile arginfo_class_Throwable_getMessage
7070

71-
#define arginfo_class_Error_getLine arginfo_class_Exception_getLine
71+
#define arginfo_class_Error_getLine arginfo_class_Throwable_getLine
7272

73-
#define arginfo_class_Error_getTrace arginfo_class_Exception_getTrace
73+
#define arginfo_class_Error_getTrace arginfo_class_Throwable_getTrace
7474

75-
#define arginfo_class_Error_getPrevious arginfo_class_Exception_getPrevious
75+
#define arginfo_class_Error_getPrevious arginfo_class_Throwable_getPrevious
7676

77-
#define arginfo_class_Error_getTraceAsString arginfo_class_Exception_getMessage
77+
#define arginfo_class_Error_getTraceAsString arginfo_class_Throwable_getMessage
7878

79-
#define arginfo_class_Error___toString arginfo_class_Exception_getMessage
79+
#define arginfo_class_Error___toString arginfo_class_Throwable_getMessage
8080

8181

8282
ZEND_METHOD(Exception, __clone);

0 commit comments

Comments
 (0)