Skip to content

Commit dc3a06f

Browse files
committed
Fixes
1 parent 4af9a2d commit dc3a06f

9 files changed

+80
-7
lines changed

Zend/tests/type_declarations/typed_class_constants_type_error2.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ try {
1313
} catch (TypeError $exception) {
1414
echo $exception->getMessage() . "\n";
1515
}
16+
17+
try {
18+
var_dump(A::CONST1);
19+
} catch (TypeError $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
22+
1623
?>
1724
--EXPECT--
1825
Cannot assign string to class constant A::CONST1 of type int
26+
Cannot assign string to class constant A::CONST1 of type int

Zend/tests/type_declarations/typed_class_constants_type_error3.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ class A {
88

99
define('C', new stdClass);
1010

11+
try {
12+
var_dump(A::CONST1);
13+
} catch (TypeError $exception) {
14+
echo $exception->getMessage() . "\n";
15+
}
16+
1117
try {
1218
var_dump(A::CONST1);
1319
} catch (TypeError $exception) {
@@ -16,3 +22,4 @@ try {
1622
?>
1723
--EXPECT--
1824
Cannot assign stdClass to class constant A::CONST1 of type string
25+
Cannot assign stdClass to class constant A::CONST1 of type string

Zend/tests/type_declarations/typed_class_constants_type_error7.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ class A {
88

99
define("C", new stdClass);
1010

11+
try {
12+
var_dump(A::CONST1);
13+
} catch (TypeError $exception) {
14+
echo $exception->getMessage() . "\n";
15+
}
16+
1117
try {
1218
var_dump(A::CONST1);
1319
} catch (TypeError $exception) {
@@ -16,3 +22,4 @@ try {
1622
?>
1723
--EXPECT--
1824
Cannot assign stdClass to class constant A::CONST1 of type stdClass&Stringable
25+
Cannot assign stdClass to class constant A::CONST1 of type stdClass&Stringable

Zend/tests/type_declarations/typed_class_constants_type_success1.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,50 @@ class A {
1717
}
1818

1919
var_dump(A::CONST1);
20+
var_dump(A::CONST1);
21+
var_dump(A::CONST2);
2022
var_dump(A::CONST2);
2123
var_dump(A::CONST3);
24+
var_dump(A::CONST3);
2225
var_dump(A::CONST4);
26+
var_dump(A::CONST4);
27+
var_dump(A::CONST5);
2328
var_dump(A::CONST5);
2429
var_dump(A::CONST6);
30+
var_dump(A::CONST6);
2531
var_dump(A::CONST7);
32+
var_dump(A::CONST7);
33+
var_dump(A::CONST8);
2634
var_dump(A::CONST8);
2735
var_dump(A::CONST9);
36+
var_dump(A::CONST9);
2837
var_dump(A::CONST10);
38+
var_dump(A::CONST10);
39+
var_dump(A::CONST11);
2940
var_dump(A::CONST11);
3041
?>
3142
--EXPECT--
3243
NULL
44+
NULL
3345
bool(false)
46+
bool(false)
47+
bool(true)
48+
bool(true)
3449
bool(true)
3550
bool(true)
3651
int(0)
52+
int(0)
53+
float(3.14)
3754
float(3.14)
3855
float(3)
56+
float(3)
3957
string(0) ""
58+
string(0) ""
59+
array(0) {
60+
}
4061
array(0) {
4162
}
4263
string(0) ""
64+
string(0) ""
65+
NULL
4366
NULL

Zend/tests/type_declarations/typed_class_constants_type_success2.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ class B implements Stringable {
1919
const C = new B();
2020

2121
var_dump(A::CONST1);
22+
var_dump(A::CONST1);
23+
var_dump(A::CONST2);
2224
var_dump(A::CONST2);
2325
var_dump(A::CONST3);
26+
var_dump(A::CONST3);
27+
var_dump(A::CONST4);
2428
var_dump(A::CONST4);
2529
var_dump(A::CONST5);
30+
var_dump(A::CONST5);
2631
?>
2732
--EXPECTF--
2833
object(B)#%d (%d) {
@@ -35,3 +40,13 @@ object(B)#%d (%d) {
3540
}
3641
object(B)#%d (%d) {
3742
}
43+
object(B)#%d (%d) {
44+
}
45+
object(B)#%d (%d) {
46+
}
47+
object(B)#%d (%d) {
48+
}
49+
object(B)#%d (%d) {
50+
}
51+
object(B)#%d (%d) {
52+
}

Zend/tests/type_declarations/typed_class_constants_type_success3.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ class A {
1818
}
1919

2020
var_dump(A::ENUM_CONST);
21+
var_dump(A::ENUM_CONST);
22+
var_dump(A::CONST1);
2123
var_dump(A::CONST1);
2224
var_dump(A::CONST2);
25+
var_dump(A::CONST2);
26+
var_dump(A::CONST3);
2327
var_dump(A::CONST3);
2428
?>
2529
--EXPECT--
2630
enum(E::Foo)
2731
enum(E::Foo)
2832
enum(E::Foo)
2933
enum(E::Foo)
34+
enum(E::Foo)
35+
enum(E::Foo)
36+
enum(E::Foo)
37+
enum(E::Foo)

Zend/zend_execute.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool s
830830

831831
ZEND_COLD zend_never_inline void zend_verify_class_constant_type_error(const zend_class_constant *c, const zval *constant)
832832
{
833+
/* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */
834+
if (EG(exception)) {
835+
return;
836+
}
837+
833838
zend_string *type_str = zend_type_to_string(c->type);
834839

835840
zend_type_error("Cannot assign %s to class constant %s::%s of type %s",

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5948,6 +5948,7 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
59485948
if (UNEXPECTED(!(c->ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
59495949
if (UNEXPECTED(zend_update_class_constants(c->ce)) != SUCCESS) {
59505950
ZVAL_UNDEF(EX_VAR(opline->result.var));
5951+
FREE_OP2();
59515952
HANDLE_EXCEPTION();
59525953
}
59535954
}
@@ -5970,7 +5971,6 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
59705971
}
59715972
}
59725973
if (OP2_TYPE == IS_CONST) {
5973-
value = &c->value;
59745974
CACHE_POLYMORPHIC_PTR(opline->extended_value, ce, value);
59755975
}
59765976
} else {

Zend/zend_vm_execute.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)