Skip to content

Commit 76db01d

Browse files
committed
Moved "Using $this when not in object context" exception code into single VM helper.
1 parent 3e6c0b7 commit 76db01d

File tree

2 files changed

+337
-870
lines changed

2 files changed

+337
-870
lines changed

Zend/zend_vm_def.h

Lines changed: 40 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,20 @@ ZEND_VM_HANDLER(13, ZEND_BOOL_NOT, CONST|TMPVAR|CV, ANY)
773773
ZEND_VM_NEXT_OPCODE();
774774
}
775775

776+
ZEND_VM_HELPER(zend_this_not_in_object_context_helper, ANY, ANY)
777+
{
778+
USE_OPLINE
779+
780+
SAVE_OPLINE();
781+
zend_throw_error(NULL, "Using $this when not in object context");
782+
if ((opline+1)->opcode == ZEND_OP_DATA) {
783+
FREE_UNFETCHED_OP_DATA();
784+
}
785+
FREE_UNFETCHED_OP2();
786+
UNDEF_RESULT();
787+
HANDLE_EXCEPTION();
788+
}
789+
776790
ZEND_VM_HELPER(zend_binary_assign_op_obj_helper, VAR|UNUSED|CV, CONST|TMPVAR|CV, binary_op_type binary_op)
777791
{
778792
USE_OPLINE
@@ -786,11 +800,7 @@ ZEND_VM_HELPER(zend_binary_assign_op_obj_helper, VAR|UNUSED|CV, CONST|TMPVAR|CV,
786800
object = GET_OP1_OBJ_ZVAL_PTR_PTR(BP_VAR_RW);
787801

788802
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
789-
zend_throw_error(NULL, "Using $this when not in object context");
790-
FREE_UNFETCHED_OP((opline+1)->op1_type, (opline+1)->op1.var);
791-
FREE_UNFETCHED_OP2();
792-
UNDEF_RESULT();
793-
HANDLE_EXCEPTION();
803+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
794804
}
795805

796806
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -1051,10 +1061,7 @@ ZEND_VM_HELPER(zend_pre_incdec_property_helper, VAR|UNUSED|CV, CONST|TMPVAR|CV,
10511061
object = GET_OP1_OBJ_ZVAL_PTR_PTR(BP_VAR_RW);
10521062

10531063
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
1054-
zend_throw_error(NULL, "Using $this when not in object context");
1055-
FREE_UNFETCHED_OP2();
1056-
UNDEF_RESULT();
1057-
HANDLE_EXCEPTION();
1064+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
10581065
}
10591066

10601067
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -1131,10 +1138,7 @@ ZEND_VM_HELPER(zend_post_incdec_property_helper, VAR|UNUSED|CV, CONST|TMPVAR|CV,
11311138
object = GET_OP1_OBJ_ZVAL_PTR_PTR(BP_VAR_RW);
11321139

11331140
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
1134-
zend_throw_error(NULL, "Using $this when not in object context");
1135-
FREE_UNFETCHED_OP2();
1136-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1137-
HANDLE_EXCEPTION();
1141+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
11381142
}
11391143

11401144
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -1756,10 +1760,7 @@ ZEND_VM_HANDLER(82, ZEND_FETCH_OBJ_R, CONST|TMP|VAR|UNUSED|THIS|CV, CONST|TMPVAR
17561760
container = GET_OP1_OBJ_ZVAL_PTR(BP_VAR_R);
17571761

17581762
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
1759-
zend_throw_error(NULL, "Using $this when not in object context");
1760-
FREE_UNFETCHED_OP2();
1761-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1762-
HANDLE_EXCEPTION();
1763+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
17631764
}
17641765

17651766
offset = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -1826,16 +1827,13 @@ ZEND_VM_HANDLER(85, ZEND_FETCH_OBJ_W, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
18261827
zval *container;
18271828

18281829
SAVE_OPLINE();
1829-
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
18301830

18311831
container = GET_OP1_OBJ_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
18321832
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
1833-
zend_throw_error(NULL, "Using $this when not in object context");
1834-
FREE_OP2();
1835-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1836-
HANDLE_EXCEPTION();
1833+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
18371834
}
18381835

1836+
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
18391837
zend_fetch_property_address(EX_VAR(opline->result.var), container, OP1_TYPE, property, OP2_TYPE, ((OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(property)) : NULL), BP_VAR_W);
18401838
FREE_OP2();
18411839
if (OP1_TYPE == IS_VAR && READY_TO_DESTROY(free_op1)) {
@@ -1853,15 +1851,12 @@ ZEND_VM_HANDLER(88, ZEND_FETCH_OBJ_RW, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
18531851
zval *container;
18541852

18551853
SAVE_OPLINE();
1856-
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
18571854
container = GET_OP1_OBJ_ZVAL_PTR_PTR(BP_VAR_RW);
18581855

18591856
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
1860-
zend_throw_error(NULL, "Using $this when not in object context");
1861-
FREE_OP2();
1862-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1863-
HANDLE_EXCEPTION();
1857+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
18641858
}
1859+
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
18651860
zend_fetch_property_address(EX_VAR(opline->result.var), container, OP1_TYPE, property, OP2_TYPE, ((OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(property)) : NULL), BP_VAR_RW);
18661861
FREE_OP2();
18671862
if (OP1_TYPE == IS_VAR && READY_TO_DESTROY(free_op1)) {
@@ -1883,10 +1878,7 @@ ZEND_VM_HANDLER(91, ZEND_FETCH_OBJ_IS, CONST|TMPVAR|UNUSED|THIS|CV, CONST|TMPVAR
18831878
container = GET_OP1_OBJ_ZVAL_PTR(BP_VAR_IS);
18841879

18851880
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
1886-
zend_throw_error(NULL, "Using $this when not in object context");
1887-
FREE_UNFETCHED_OP2();
1888-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1889-
HANDLE_EXCEPTION();
1881+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
18901882
}
18911883

18921884
offset = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -1956,22 +1948,19 @@ ZEND_VM_HANDLER(94, ZEND_FETCH_OBJ_FUNC_ARG, CONST|TMP|VAR|UNUSED|THIS|CV, CONST
19561948
zval *property;
19571949

19581950
SAVE_OPLINE();
1959-
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
19601951
container = GET_OP1_OBJ_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
19611952

19621953
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
1963-
zend_throw_error(NULL, "Using $this when not in object context");
1964-
FREE_OP2();
1965-
ZVAL_UNDEF(EX_VAR(opline->result.var));
1966-
HANDLE_EXCEPTION();
1954+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
19671955
}
19681956
if ((OP1_TYPE & (IS_CONST|IS_TMP_VAR))) {
19691957
zend_throw_error(NULL, "Cannot use temporary expression in write context");
1970-
FREE_OP2();
1958+
FREE_UNFETCHED_OP2();
19711959
FREE_OP1_VAR_PTR();
19721960
ZVAL_UNDEF(EX_VAR(opline->result.var));
19731961
HANDLE_EXCEPTION();
19741962
}
1963+
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
19751964
zend_fetch_property_address(EX_VAR(opline->result.var), container, OP1_TYPE, property, OP2_TYPE, ((OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(property)) : NULL), BP_VAR_W);
19761965
FREE_OP2();
19771966
if (OP1_TYPE == IS_VAR && READY_TO_DESTROY(free_op1)) {
@@ -1994,10 +1983,7 @@ ZEND_VM_HANDLER(97, ZEND_FETCH_OBJ_UNSET, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
19941983
container = GET_OP1_OBJ_ZVAL_PTR_PTR(BP_VAR_UNSET);
19951984

19961985
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
1997-
zend_throw_error(NULL, "Using $this when not in object context");
1998-
FREE_UNFETCHED_OP2();
1999-
ZVAL_UNDEF(EX_VAR(opline->result.var));
2000-
HANDLE_EXCEPTION();
1986+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
20011987
}
20021988

20031989
property = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -2034,11 +2020,7 @@ ZEND_VM_HANDLER(136, ZEND_ASSIGN_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, SPEC(
20342020
object = GET_OP1_OBJ_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
20352021

20362022
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
2037-
zend_throw_error(NULL, "Using $this when not in object context");
2038-
FREE_UNFETCHED_OP2();
2039-
FREE_UNFETCHED_OP_DATA();
2040-
UNDEF_RESULT();
2041-
HANDLE_EXCEPTION();
2023+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
20422024
}
20432025

20442026
property_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -2922,6 +2904,12 @@ ZEND_VM_HANDLER(112, ZEND_INIT_METHOD_CALL, CONST|TMPVAR|UNUSED|THIS|CV, CONST|T
29222904

29232905
SAVE_OPLINE();
29242906

2907+
object = GET_OP1_OBJ_ZVAL_PTR_UNDEF(BP_VAR_R);
2908+
2909+
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
2910+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
2911+
}
2912+
29252913
function_name = GET_OP2_ZVAL_PTR_UNDEF(BP_VAR_R);
29262914

29272915
if (OP2_TYPE != IS_CONST &&
@@ -2935,24 +2923,17 @@ ZEND_VM_HANDLER(112, ZEND_INIT_METHOD_CALL, CONST|TMPVAR|UNUSED|THIS|CV, CONST|T
29352923
} else if (OP2_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(function_name) == IS_UNDEF)) {
29362924
GET_OP2_UNDEF_CV(function_name, BP_VAR_R);
29372925
if (UNEXPECTED(EG(exception) != NULL)) {
2926+
FREE_OP1();
29382927
HANDLE_EXCEPTION();
29392928
}
29402929
}
29412930
zend_throw_error(NULL, "Method name must be a string");
29422931
FREE_OP2();
2943-
FREE_UNFETCHED_OP1();
2932+
FREE_OP1();
29442933
HANDLE_EXCEPTION();
29452934
} while (0);
29462935
}
29472936

2948-
object = GET_OP1_OBJ_ZVAL_PTR_UNDEF(BP_VAR_R);
2949-
2950-
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) == IS_UNDEF)) {
2951-
zend_throw_error(NULL, "Using $this when not in object context");
2952-
FREE_OP2();
2953-
HANDLE_EXCEPTION();
2954-
}
2955-
29562937
if (OP1_TYPE != IS_UNUSED) {
29572938
do {
29582939
if (OP1_TYPE == IS_CONST || UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
@@ -4881,9 +4862,7 @@ ZEND_VM_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
48814862
obj = GET_OP1_OBJ_ZVAL_PTR_UNDEF(BP_VAR_R);
48824863

48834864
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(obj) == IS_UNDEF)) {
4884-
zend_throw_error(NULL, "Using $this when not in object context");
4885-
ZVAL_UNDEF(EX_VAR(opline->result.var));
4886-
HANDLE_EXCEPTION();
4865+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
48874866
}
48884867

48894868
do {
@@ -5554,9 +5533,7 @@ ZEND_VM_HANDLER(76, ZEND_UNSET_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
55545533
SAVE_OPLINE();
55555534
container = GET_OP1_OBJ_ZVAL_PTR_PTR(BP_VAR_UNSET);
55565535
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
5557-
zend_throw_error(NULL, "Using $this when not in object context");
5558-
FREE_UNFETCHED_OP2();
5559-
HANDLE_EXCEPTION();
5536+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
55605537
}
55615538
offset = GET_OP2_ZVAL_PTR(BP_VAR_R);
55625539

@@ -6553,10 +6530,7 @@ ZEND_VM_HANDLER(148, ZEND_ISSET_ISEMPTY_PROP_OBJ, CONST|TMPVAR|UNUSED|THIS|CV, C
65536530
container = GET_OP1_OBJ_ZVAL_PTR(BP_VAR_IS);
65546531

65556532
if (OP1_TYPE == IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
6556-
zend_throw_error(NULL, "Using $this when not in object context");
6557-
FREE_UNFETCHED_OP2();
6558-
ZVAL_UNDEF(EX_VAR(opline->result.var));
6559-
HANDLE_EXCEPTION();
6533+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
65606534
}
65616535

65626536
offset = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -8040,10 +8014,7 @@ ZEND_VM_HANDLER(184, ZEND_FETCH_THIS, UNUSED, UNUSED)
80408014
Z_ADDREF_P(result);
80418015
ZEND_VM_NEXT_OPCODE();
80428016
} else {
8043-
SAVE_OPLINE();
8044-
zend_throw_error(NULL, "Using $this when not in object context");
8045-
ZVAL_UNDEF(EX_VAR(opline->result.var));
8046-
HANDLE_EXCEPTION();
8017+
ZEND_VM_DISPATCH_TO_HELPER(zend_this_not_in_object_context_helper);
80478018
}
80488019
}
80498020

0 commit comments

Comments
 (0)