Skip to content

Commit fd0b3ea

Browse files
committed
Fixed bug #61442 (exception threw in __autoload can not be catched)
1 parent 6752f38 commit fd0b3ea

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
some builtin classes). (Laruence)
1010
. Fixed bug #61767 (Shutdown functions not called in certain error
1111
situation). (Dmitry)
12+
. Fixed bug #61442 (exception threw in __autoload can not be catched).
13+
(Laruence)
1214
. Fixed bug #60909 (custom error handler throwing Exception + fatal error
1315
= no shutdown function). (Dmitry)
1416

Zend/tests/bug61442.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #61442 (exception threw in __autoload can not be catched)
3+
--FILE--
4+
<?php
5+
function __autoload($name) {
6+
throw new Exception("Unable to load $name");
7+
}
8+
9+
try {
10+
$obj = new NonLoadableClass();
11+
} catch (Exception $e) {
12+
var_dump($e->getMessage());
13+
}
14+
15+
try {
16+
$obj = NonLoadableClass::a();
17+
} catch (Exception $e) {
18+
var_dump($e->getMessage());
19+
}
20+
21+
try {
22+
$obj = NonLoadableClass::UNDEFINED_CONST;
23+
} catch (Exception $e) {
24+
var_dump($e->getMessage());
25+
}
26+
27+
--EXPECTF--
28+
string(31) "Unable to load NonLoadableClass"
29+
string(31) "Unable to load NonLoadableClass"
30+
string(31) "Unable to load NonLoadableClass"

Zend/zend_vm_def.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,9 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMP|VAR|UNUS
19901990
if (OP1_TYPE == IS_CONST) {
19911991
/* no function found. try a static method in class */
19921992
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
1993+
if (UNEXPECTED(EG(exception) != NULL)) {
1994+
ZEND_VM_CONTINUE();
1995+
}
19931996
if (!ce) {
19941997
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
19951998
}
@@ -3043,6 +3046,9 @@ ZEND_VM_HANDLER(99, ZEND_FETCH_CONSTANT, VAR|CONST|UNUSED, CONST)
30433046
if (OP1_TYPE == IS_CONST) {
30443047

30453048
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
3049+
if (UNEXPECTED(EG(exception) != NULL)) {
3050+
ZEND_VM_CONTINUE();
3051+
}
30463052
if (!ce) {
30473053
zend_error_noreturn(E_ERROR, "Undefined class constant '%s'", Z_STRVAL(opline->op2.u.constant));
30483054
}

Zend/zend_vm_execute.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CONST_HANDLER(
26882688
if (IS_CONST == IS_CONST) {
26892689
/* no function found. try a static method in class */
26902690
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
2691+
if (UNEXPECTED(EG(exception) != NULL)) {
2692+
ZEND_VM_CONTINUE();
2693+
}
26912694
if (!ce) {
26922695
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
26932696
}
@@ -2836,6 +2839,9 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCO
28362839
if (IS_CONST == IS_CONST) {
28372840

28382841
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
2842+
if (UNEXPECTED(EG(exception) != NULL)) {
2843+
ZEND_VM_CONTINUE();
2844+
}
28392845
if (!ce) {
28402846
zend_error_noreturn(E_ERROR, "Undefined class constant '%s'", Z_STRVAL(opline->op2.u.constant));
28412847
}
@@ -3259,6 +3265,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_TMP_HANDLER(ZE
32593265
if (IS_CONST == IS_CONST) {
32603266
/* no function found. try a static method in class */
32613267
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
3268+
if (UNEXPECTED(EG(exception) != NULL)) {
3269+
ZEND_VM_CONTINUE();
3270+
}
32623271
if (!ce) {
32633272
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
32643273
}
@@ -3725,6 +3734,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_VAR_HANDLER(ZE
37253734
if (IS_CONST == IS_CONST) {
37263735
/* no function found. try a static method in class */
37273736
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
3737+
if (UNEXPECTED(EG(exception) != NULL)) {
3738+
ZEND_VM_CONTINUE();
3739+
}
37283740
if (!ce) {
37293741
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
37303742
}
@@ -3947,6 +3959,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_UNUSED_HANDLER
39473959
if (IS_CONST == IS_CONST) {
39483960
/* no function found. try a static method in class */
39493961
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
3962+
if (UNEXPECTED(EG(exception) != NULL)) {
3963+
ZEND_VM_CONTINUE();
3964+
}
39503965
if (!ce) {
39513966
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
39523967
}
@@ -4381,6 +4396,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_CV_HANDLER(ZEN
43814396
if (IS_CONST == IS_CONST) {
43824397
/* no function found. try a static method in class */
43834398
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
4399+
if (UNEXPECTED(EG(exception) != NULL)) {
4400+
ZEND_VM_CONTINUE();
4401+
}
43844402
if (!ce) {
43854403
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
43864404
}
@@ -10498,6 +10516,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZE
1049810516
if (IS_VAR == IS_CONST) {
1049910517
/* no function found. try a static method in class */
1050010518
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
10519+
if (UNEXPECTED(EG(exception) != NULL)) {
10520+
ZEND_VM_CONTINUE();
10521+
}
1050110522
if (!ce) {
1050210523
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
1050310524
}
@@ -10646,6 +10667,9 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE
1064610667
if (IS_VAR == IS_CONST) {
1064710668

1064810669
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
10670+
if (UNEXPECTED(EG(exception) != NULL)) {
10671+
ZEND_VM_CONTINUE();
10672+
}
1064910673
if (!ce) {
1065010674
zend_error_noreturn(E_ERROR, "Undefined class constant '%s'", Z_STRVAL(opline->op2.u.constant));
1065110675
}
@@ -12305,6 +12329,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND
1230512329
if (IS_VAR == IS_CONST) {
1230612330
/* no function found. try a static method in class */
1230712331
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
12332+
if (UNEXPECTED(EG(exception) != NULL)) {
12333+
ZEND_VM_CONTINUE();
12334+
}
1230812335
if (!ce) {
1230912336
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
1231012337
}
@@ -14107,6 +14134,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND
1410714134
if (IS_VAR == IS_CONST) {
1410814135
/* no function found. try a static method in class */
1410914136
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
14137+
if (UNEXPECTED(EG(exception) != NULL)) {
14138+
ZEND_VM_CONTINUE();
14139+
}
1411014140
if (!ce) {
1411114141
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
1411214142
}
@@ -15003,6 +15033,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_UNUSED_HANDLER(Z
1500315033
if (IS_VAR == IS_CONST) {
1500415034
/* no function found. try a static method in class */
1500515035
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
15036+
if (UNEXPECTED(EG(exception) != NULL)) {
15037+
ZEND_VM_CONTINUE();
15038+
}
1500615039
if (!ce) {
1500715040
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
1500815041
}
@@ -16496,6 +16529,9 @@ static int ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_
1649616529
if (IS_VAR == IS_CONST) {
1649716530
/* no function found. try a static method in class */
1649816531
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
16532+
if (UNEXPECTED(EG(exception) != NULL)) {
16533+
ZEND_VM_CONTINUE();
16534+
}
1649916535
if (!ce) {
1650016536
zend_error_noreturn(E_ERROR, "Class '%s' not found", Z_STRVAL(opline->op1.u.constant));
1650116537
}
@@ -17860,6 +17896,9 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPC
1786017896
if (IS_UNUSED == IS_CONST) {
1786117897

1786217898
ce = zend_fetch_class(Z_STRVAL(opline->op1.u.constant), Z_STRLEN(opline->op1.u.constant), opline->extended_value TSRMLS_CC);
17899+
if (UNEXPECTED(EG(exception) != NULL)) {
17900+
ZEND_VM_CONTINUE();
17901+
}
1786317902
if (!ce) {
1786417903
zend_error_noreturn(E_ERROR, "Undefined class constant '%s'", Z_STRVAL(opline->op2.u.constant));
1786517904
}

0 commit comments

Comments
 (0)