Skip to content

Commit 213b666

Browse files
committed
Synchronize GET_CLASS/GET_CALLED_CLASS opcodes with functions
These error conditions throw in the function implementations, make the opcodes match.
1 parent d085a74 commit 213b666

File tree

5 files changed

+40
-41
lines changed

5 files changed

+40
-41
lines changed

Zend/tests/009.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ $f2 = new foo2;
2626
$f1->bar();
2727
$f2->bar();
2828

29-
var_dump(get_class());
29+
try {
30+
var_dump(get_class());
31+
} catch (Error $e) {
32+
echo $e->getMessage(), "\n";
33+
}
3034
try {
3135
var_dump(get_class("qwerty"));
3236
} catch (TypeError $e) {
@@ -40,12 +44,10 @@ $f1->testNull();
4044

4145
echo "Done\n";
4246
?>
43-
--EXPECTF--
47+
--EXPECT--
4448
string(3) "foo"
4549
string(3) "foo"
46-
47-
Warning: get_class() called without object from outside a class in %s on line %d
48-
bool(false)
50+
get_class() without arguments must be called from within a class
4951
get_class(): Argument #1 ($object) must be of type object, string given
5052
string(3) "foo"
5153
string(4) "foo2"

Zend/tests/bug47054.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ C::s();
2222
$c = new C();
2323
$c->s();
2424

25-
get_called_class();
26-
2725
?>
28-
--EXPECTF--
26+
--EXPECT--
2927
Called class: D
3028
Called class: C
3129
Called class: C
32-
33-
Warning: get_called_class() called from outside a class in %s on line %d

Zend/tests/get_called_class_001.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Calling get_called_class() outside a class
33
--FILE--
44
<?php
55

6-
var_dump(get_called_class());
6+
try {
7+
var_dump(get_called_class());
8+
} catch (Error $e) {
9+
echo $e->getMessage(), "\n";
10+
}
711

812
?>
9-
--EXPECTF--
10-
Warning: get_called_class() called from outside a class in %s on line %d
11-
bool(false)
13+
--EXPECT--
14+
get_called_class() must be called from within a class

Zend/zend_vm_def.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8940,9 +8940,9 @@ ZEND_VM_COLD_CONST_HANDLER(191, ZEND_GET_CLASS, UNUSED|CONST|TMPVAR|CV, UNUSED)
89408940
if (OP1_TYPE == IS_UNUSED) {
89418941
if (UNEXPECTED(!EX(func)->common.scope)) {
89428942
SAVE_OPLINE();
8943-
zend_error(E_WARNING, "get_class() called without object from outside a class");
8944-
ZVAL_FALSE(EX_VAR(opline->result.var));
8945-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
8943+
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
8944+
ZVAL_UNDEF(EX_VAR(opline->result.var));
8945+
HANDLE_EXCEPTION();
89468946
} else {
89478947
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
89488948
ZEND_VM_NEXT_OPCODE();
@@ -8981,12 +8981,11 @@ ZEND_VM_HANDLER(192, ZEND_GET_CALLED_CLASS, UNUSED, UNUSED)
89818981
} else if (Z_CE(EX(This))) {
89828982
ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_CE(EX(This))->name);
89838983
} else {
8984-
ZVAL_FALSE(EX_VAR(opline->result.var));
8985-
if (UNEXPECTED(!EX(func)->common.scope)) {
8986-
SAVE_OPLINE();
8987-
zend_error(E_WARNING, "get_called_class() called from outside a class");
8988-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
8989-
}
8984+
ZEND_ASSERT(!EX(func)->common.scope);
8985+
SAVE_OPLINE();
8986+
zend_throw_error(NULL, "get_called_class() must be called from within a class");
8987+
ZVAL_UNDEF(EX_VAR(opline->result.var));
8988+
HANDLE_EXCEPTION();
89908989
}
89918990
ZEND_VM_NEXT_OPCODE();
89928991
}

Zend/zend_vm_execute.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10381,9 +10381,9 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_CO
1038110381
if (IS_CONST == IS_UNUSED) {
1038210382
if (UNEXPECTED(!EX(func)->common.scope)) {
1038310383
SAVE_OPLINE();
10384-
zend_error(E_WARNING, "get_class() called without object from outside a class");
10385-
ZVAL_FALSE(EX_VAR(opline->result.var));
10386-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
10384+
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
10385+
ZVAL_UNDEF(EX_VAR(opline->result.var));
10386+
HANDLE_EXCEPTION();
1038710387
} else {
1038810388
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
1038910389
ZEND_VM_NEXT_OPCODE();
@@ -17624,9 +17624,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_TMPVAR_UNUSED_H
1762417624
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
1762517625
if (UNEXPECTED(!EX(func)->common.scope)) {
1762617626
SAVE_OPLINE();
17627-
zend_error(E_WARNING, "get_class() called without object from outside a class");
17628-
ZVAL_FALSE(EX_VAR(opline->result.var));
17629-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
17627+
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
17628+
ZVAL_UNDEF(EX_VAR(opline->result.var));
17629+
HANDLE_EXCEPTION();
1763017630
} else {
1763117631
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
1763217632
ZEND_VM_NEXT_OPCODE();
@@ -35225,9 +35225,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_UNUSED_UNUSED_H
3522535225
if (IS_UNUSED == IS_UNUSED) {
3522635226
if (UNEXPECTED(!EX(func)->common.scope)) {
3522735227
SAVE_OPLINE();
35228-
zend_error(E_WARNING, "get_class() called without object from outside a class");
35229-
ZVAL_FALSE(EX_VAR(opline->result.var));
35230-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
35228+
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
35229+
ZVAL_UNDEF(EX_VAR(opline->result.var));
35230+
HANDLE_EXCEPTION();
3523135231
} else {
3523235232
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
3523335233
ZEND_VM_NEXT_OPCODE();
@@ -35266,12 +35266,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CALLED_CLASS_SPEC_UNUSED_U
3526635266
} else if (Z_CE(EX(This))) {
3526735267
ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_CE(EX(This))->name);
3526835268
} else {
35269-
ZVAL_FALSE(EX_VAR(opline->result.var));
35270-
if (UNEXPECTED(!EX(func)->common.scope)) {
35271-
SAVE_OPLINE();
35272-
zend_error(E_WARNING, "get_called_class() called from outside a class");
35273-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
35274-
}
35269+
ZEND_ASSERT(!EX(func)->common.scope);
35270+
SAVE_OPLINE();
35271+
zend_throw_error(NULL, "get_called_class() must be called from within a class");
35272+
ZVAL_UNDEF(EX_VAR(opline->result.var));
35273+
HANDLE_EXCEPTION();
3527535274
}
3527635275
ZEND_VM_NEXT_OPCODE();
3527735276
}
@@ -47385,9 +47384,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GET_CLASS_SPEC_CV_UNUSED_HANDL
4738547384
if (IS_CV == IS_UNUSED) {
4738647385
if (UNEXPECTED(!EX(func)->common.scope)) {
4738747386
SAVE_OPLINE();
47388-
zend_error(E_WARNING, "get_class() called without object from outside a class");
47389-
ZVAL_FALSE(EX_VAR(opline->result.var));
47390-
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
47387+
zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
47388+
ZVAL_UNDEF(EX_VAR(opline->result.var));
47389+
HANDLE_EXCEPTION();
4739147390
} else {
4739247391
ZVAL_STR_COPY(EX_VAR(opline->result.var), EX(func)->common.scope->name);
4739347392
ZEND_VM_NEXT_OPCODE();

0 commit comments

Comments
 (0)