Skip to content

Commit 32f58fd

Browse files
committed
Make some Exception properties typed
1 parent 8b6a2d5 commit 32f58fd

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

Zend/tests/bug50005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #50005 (Throwing through Reflection modified Exception object makes segmenta
55

66
class a extends exception {
77
public function __construct() {
8-
$this->file = null;
8+
$this->file = "";
99
}
1010
}
1111

Zend/tests/bug64821.1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class a extends exception {
88
$this->message = NULL;
99
$this->string = NULL;
1010
$this->code = array();
11-
$this->line = "hello";
11+
$this->line = 0;
1212
}
1313
}
1414

Zend/tests/bug64821.2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #64821 Custom Exceptions crash when internal properties overridden (variatio
55

66
class a extends exception {
77
public function __construct() {
8-
$this->line = array();
8+
$this->line = 0;
99
}
1010
}
1111

Zend/tests/bug64821.3.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Bug #64821 Custom Exceptions crash when internal properties overridden (variatio
55

66
class a extends exception {
77
public function __construct() {
8-
$this->line = array();
9-
$this->file = NULL;
8+
$this->line = 0;
9+
$this->file = "";
1010
}
1111
}
1212

Zend/zend_exceptions.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,13 @@ void zend_register_default_exception(void) /* {{{ */
757757

758758
zend_ce_error_exception = register_class_ErrorException(zend_ce_exception);
759759
zend_ce_error_exception->create_object = zend_error_exception_new;
760+
760761
/* Declared manually because it uses constant E_ERROR. */
761-
zend_declare_property_long(zend_ce_error_exception, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED);
762+
zval severity_default_value;
763+
ZVAL_LONG(&severity_default_value, E_ERROR);
764+
zend_string *severity_name = zend_string_init("severity", sizeof("severity") - 1, 1);
765+
zend_declare_typed_property(zend_ce_error_exception, severity_name, &severity_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
766+
zend_string_release(severity_name);
762767

763768
zend_ce_error = register_class_Error(zend_ce_throwable);
764769
zend_ce_error->create_object = zend_default_exception_new;

Zend/zend_exceptions.stub.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ class Exception implements Throwable
2424
{
2525
/** @var string */
2626
protected $message = "";
27-
/** @var string */
28-
private $string = "";
27+
private string $string = "";
2928
/** @var int */
3029
protected $code = 0;
31-
/** @var string|null */
32-
protected $file = null;
33-
/** @var int|null */
34-
protected $line = null;
30+
protected string $file = "";
31+
protected int $line = 0;
3532
private array $trace = [];
3633
private ?Throwable $previous = null;
3734

@@ -62,8 +59,7 @@ public function __toString(): string {}
6259

6360
class ErrorException extends Exception
6461
{
65-
/** @var int */
66-
protected $severity = E_ERROR;
62+
protected int $severity = E_ERROR;
6763

6864
public function __construct(
6965
string $message = "",
@@ -81,14 +77,11 @@ class Error implements Throwable
8177
{
8278
/** @var string */
8379
protected $message = "";
84-
/** @var string */
85-
private $string = "";
80+
private string $string = "";
8681
/** @var int */
8782
protected $code = 0;
88-
/** @var string|null */
89-
protected $file = null;
90-
/** @var int|null */
91-
protected $line = null;
83+
protected string $file = "";
84+
protected int $line;
9285
private array $trace = [];
9386
private ?Throwable $previous = null;
9487

Zend/zend_exceptions_arginfo.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: f322ba2ed3e636b6e99400edfbff98102b7e3d06 */
2+
* Stub hash: 22f63cd88945d9c98fac0a05ff7d75861c4722e6 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -214,7 +214,7 @@ static zend_class_entry *register_class_Exception(zend_class_entry *class_entry_
214214
zval property_string_default_value;
215215
ZVAL_EMPTY_STRING(&property_string_default_value);
216216
zend_string *property_string_name = zend_string_init("string", sizeof("string") - 1, 1);
217-
zend_declare_property_ex(class_entry, property_string_name, &property_string_default_value, ZEND_ACC_PRIVATE, NULL);
217+
zend_declare_typed_property(class_entry, property_string_name, &property_string_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
218218
zend_string_release(property_string_name);
219219

220220
zval property_code_default_value;
@@ -224,15 +224,15 @@ static zend_class_entry *register_class_Exception(zend_class_entry *class_entry_
224224
zend_string_release(property_code_name);
225225

226226
zval property_file_default_value;
227-
ZVAL_NULL(&property_file_default_value);
227+
ZVAL_EMPTY_STRING(&property_file_default_value);
228228
zend_string *property_file_name = zend_string_init("file", sizeof("file") - 1, 1);
229-
zend_declare_property_ex(class_entry, property_file_name, &property_file_default_value, ZEND_ACC_PROTECTED, NULL);
229+
zend_declare_typed_property(class_entry, property_file_name, &property_file_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
230230
zend_string_release(property_file_name);
231231

232232
zval property_line_default_value;
233-
ZVAL_NULL(&property_line_default_value);
233+
ZVAL_LONG(&property_line_default_value, 0);
234234
zend_string *property_line_name = zend_string_init("line", sizeof("line") - 1, 1);
235-
zend_declare_property_ex(class_entry, property_line_name, &property_line_default_value, ZEND_ACC_PROTECTED, NULL);
235+
zend_declare_typed_property(class_entry, property_line_name, &property_line_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
236236
zend_string_release(property_line_name);
237237

238238
zval property_trace_default_value;
@@ -278,7 +278,7 @@ static zend_class_entry *register_class_Error(zend_class_entry *class_entry_Thro
278278
zval property_string_default_value;
279279
ZVAL_EMPTY_STRING(&property_string_default_value);
280280
zend_string *property_string_name = zend_string_init("string", sizeof("string") - 1, 1);
281-
zend_declare_property_ex(class_entry, property_string_name, &property_string_default_value, ZEND_ACC_PRIVATE, NULL);
281+
zend_declare_typed_property(class_entry, property_string_name, &property_string_default_value, ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
282282
zend_string_release(property_string_name);
283283

284284
zval property_code_default_value;
@@ -288,15 +288,15 @@ static zend_class_entry *register_class_Error(zend_class_entry *class_entry_Thro
288288
zend_string_release(property_code_name);
289289

290290
zval property_file_default_value;
291-
ZVAL_NULL(&property_file_default_value);
291+
ZVAL_EMPTY_STRING(&property_file_default_value);
292292
zend_string *property_file_name = zend_string_init("file", sizeof("file") - 1, 1);
293-
zend_declare_property_ex(class_entry, property_file_name, &property_file_default_value, ZEND_ACC_PROTECTED, NULL);
293+
zend_declare_typed_property(class_entry, property_file_name, &property_file_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
294294
zend_string_release(property_file_name);
295295

296296
zval property_line_default_value;
297-
ZVAL_NULL(&property_line_default_value);
297+
ZVAL_UNDEF(&property_line_default_value);
298298
zend_string *property_line_name = zend_string_init("line", sizeof("line") - 1, 1);
299-
zend_declare_property_ex(class_entry, property_line_name, &property_line_default_value, ZEND_ACC_PROTECTED, NULL);
299+
zend_declare_typed_property(class_entry, property_line_name, &property_line_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
300300
zend_string_release(property_line_name);
301301

302302
zval property_trace_default_value;

0 commit comments

Comments
 (0)