Skip to content

Commit 00d1510

Browse files
committed
refine some error messages
1 parent 24adac5 commit 00d1510

File tree

9 files changed

+60
-39
lines changed

9 files changed

+60
-39
lines changed

Zend/zend_vm_def.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ ZEND_VM_HANDLER(210, ZEND_FETCH_INNER_CLASS, CONST|TMPVAR|UNUSED, CONST, CACHE_S
18121812
zval *outer_class_zv = RT_CONSTANT(opline, opline->op1);
18131813
outer_ce = zend_lookup_class(Z_STR_P(outer_class_zv));
18141814
if (!outer_ce) {
1815-
zend_error(E_ERROR, "Class '%s' not found", Z_STRVAL_P(outer_class_zv));
1815+
zend_error(E_ERROR, "Outer class '%s' not found for inner class %s:>%s", Z_STRVAL_P(outer_class_zv), Z_STRVAL_P(outer_class_zv), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
18161816
HANDLE_EXCEPTION();
18171817
}
18181818
} else if (OP1_TYPE == IS_UNUSED) {
@@ -1864,7 +1864,7 @@ ZEND_VM_HANDLER(210, ZEND_FETCH_INNER_CLASS, CONST|TMPVAR|UNUSED, CONST, CACHE_S
18641864

18651865
inner_ce = zend_lookup_class(full_class_name);
18661866
if (!inner_ce) {
1867-
zend_error(E_ERROR, "Class '%s' not found", ZSTR_VAL(full_class_name));
1867+
zend_error(E_ERROR, "Inner class '%s' not found in outer class %s", ZSTR_VAL(full_class_name), ZSTR_VAL(outer_ce->name));
18681868
HANDLE_EXCEPTION();
18691869
}
18701870

@@ -1874,15 +1874,15 @@ ZEND_VM_HANDLER(210, ZEND_FETCH_INNER_CLASS, CONST|TMPVAR|UNUSED, CONST, CACHE_S
18741874
if (scope != NULL && (inner_ce->required_scope == scope || scope->lexical_scope == inner_ce->required_scope)) {
18751875
// we are in the correct scope
18761876
} else {
1877-
zend_error(E_ERROR, "Class '%s' is private", ZSTR_VAL(full_class_name));
1877+
zend_error(E_ERROR, "Cannot access private inner class '%s'", ZSTR_VAL(full_class_name));
18781878
HANDLE_EXCEPTION();
18791879
}
18801880
} else {
18811881
// for protected classes, we check if the scope is an instance of the required scope
18821882
if (scope != NULL && (instanceof_function(scope, inner_ce->required_scope) || instanceof_function(scope->lexical_scope, inner_ce->required_scope))) {
18831883
// we are in the correct scope
18841884
} else {
1885-
zend_error(E_ERROR, "Class '%s' is protected", ZSTR_VAL(full_class_name));
1885+
zend_error(E_ERROR, "Cannot access protected inner class '%s'", ZSTR_VAL(full_class_name));
18861886
HANDLE_EXCEPTION();
18871887
}
18881888
}
@@ -4529,15 +4529,15 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
45294529
if (Z_OBJCE_P(retval_ptr)->required_scope) {
45304530
if (EX(func)->common.fn_flags & ZEND_ACC_PUBLIC) {
45314531
if (Z_OBJCE_P(retval_ptr)->required_scope_absolute) {
4532-
zend_type_error("Method %s is public but returns a private class: %s", ZSTR_VAL(EX(func)->common.function_name), ZSTR_VAL(Z_OBJCE_P(retval_ptr)->name));
4532+
zend_type_error("Public method %s cannot return private class %s", ZSTR_VAL(EX(func)->common.function_name), ZSTR_VAL(Z_OBJCE_P(retval_ptr)->name));
45334533
HANDLE_EXCEPTION();
45344534
} else {
4535-
zend_type_error("Method %s is public but returns a protected class: %s", ZSTR_VAL(EX(func)->common.function_name), ZSTR_VAL(Z_OBJCE_P(retval_ptr)->name));
4535+
zend_type_error("Public method %s cannot return protected class %s", ZSTR_VAL(EX(func)->common.function_name), ZSTR_VAL(Z_OBJCE_P(retval_ptr)->name));
45364536
HANDLE_EXCEPTION();
45374537
}
45384538
} else if (EX(func)->common.fn_flags & ZEND_ACC_PROTECTED) {
45394539
if (Z_OBJCE_P(retval_ptr)->required_scope_absolute && Z_OBJCE_P(retval_ptr)->required_scope != EX(func)->common.scope) {
4540-
zend_type_error("Method %s is protected but returns a private class: %s", ZSTR_VAL(EX(func)->common.function_name), ZSTR_VAL(Z_OBJCE_P(retval_ptr)->name));
4540+
zend_type_error("Protected method %s cannot return private class %s", ZSTR_VAL(EX(func)->common.function_name), ZSTR_VAL(Z_OBJCE_P(retval_ptr)->name));
45414541
HANDLE_EXCEPTION();
45424542
}
45434543
}

Zend/zend_vm_execute.h

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

tests/classes/inner_classes/autoload_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ var_dump($line);
1313
--EXPECTF--
1414
autoload(inner_classes)
1515

16-
Fatal error: Class 'inner_classes:>Line' is private in %s on line %d
16+
Fatal error: Cannot access private inner class 'inner_classes:>Line' in %s
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
no outer class
3+
--FILE--
4+
<?php
5+
6+
new Outer:>Inner();
7+
?>
8+
--EXPECTF--
9+
Fatal error: Outer class 'Outer' not found for inner class Outer:>Inner in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
inner class not found
3+
--FILE--
4+
<?php
5+
6+
class Outer {
7+
}
8+
9+
new Outer:>Inner();
10+
?>
11+
--EXPECTF--
12+
Fatal error: Inner class 'Outer:>Inner' not found in outer class Outer in %s on line %d

tests/classes/inner_classes/return_types_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ var_dump($outer->getInner());
2929
object(Outer:>Inner)#2 (0) {
3030
}
3131

32-
Fatal error: Class 'Outer:>Inner' is private in %s on line %d
32+
Fatal error: Cannot access private inner class 'Outer:>Inner' in %s on line %d

tests/classes/inner_classes/return_types_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var_dump(new Outer:>Inner());
2626
object(Outer:>Inner)#2 (0) {
2727
}
2828

29-
Fatal error: Uncaught TypeError: Method getInner is public but returns a protected class: Outer:>Inner in %s:%d
29+
Fatal error: Uncaught TypeError: Public method getInner cannot return protected class Outer:>Inner in %s:%d
3030
Stack trace:
3131
#0 %s(%d): Foo->getInner()
3232
#1 {main}

tests/classes/inner_classes/return_types_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var_dump($r);
1919
test($r);
2020
?>
2121
--EXPECTF--
22-
Fatal error: Uncaught TypeError: Method getInner is public but returns a private class: Outer:>Inner in %s:%d
22+
Fatal error: Uncaught TypeError: Public method getInner cannot return private class Outer:>Inner in %s:%d
2323
Stack trace:
2424
#0 %s(%d): Outer::getInner()
2525
#1 {main}

tests/classes/inner_classes/return_types_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var_dump($r);
1919
test($r);
2020
?>
2121
--EXPECTF--
22-
Fatal error: Uncaught TypeError: Method getInner is public but returns a protected class: Outer:>Inner in %s:%d
22+
Fatal error: Uncaught TypeError: Public method getInner cannot return protected class Outer:>Inner in %s:%d
2323
Stack trace:
2424
#0 %s(%d): Outer::getInner()
2525
#1 {main}

0 commit comments

Comments
 (0)