Skip to content

Commit 5c8bd44

Browse files
committed
Make compatible with PHP 8
1 parent ddc1f4b commit 5c8bd44

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

scalar_objects.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ typedef size_t strlen_t;
2121
# define EX_LITERAL(opline, op) EX_CONSTANT(op)
2222
#endif
2323
#define SO_THIS (Z_OBJ(EX(This)) ? &EX(This) : NULL)
24-
#define FREE_OP(should_free) \
25-
if (should_free) { \
26-
zval_ptr_dtor_nogc(should_free); \
24+
#define FREE_OP(op) \
25+
if (opline->op##_type & (IS_TMP_VAR|IS_VAR)) { \
26+
zval_ptr_dtor_nogc(EX_VAR(opline->op.var)); \
2727
}
28-
#define FREE_OP_IF_VAR(should_free) FREE_OP(should_free)
2928

3029
#define SO_EX_CV(i) (*EX_CV_NUM(execute_data, i))
3130
#define SO_EX_T(offset) (*EX_TMP_VAR(execute_data, offset))
@@ -63,11 +62,15 @@ static zval *get_object_zval_ptr_safe(
6362

6463
static zval *get_zval_ptr_real(
6564
const zend_op *opline, int op_type, const znode_op *node,
66-
const zend_execute_data *execute_data, zend_free_op *should_free, int type
65+
const zend_execute_data *execute_data, int type
6766
) {
68-
#if PHP_VERSION_ID >= 70300
67+
#if PHP_VERSION_ID >= 80000
68+
zval *zv = zend_get_zval_ptr(opline, op_type, node, execute_data, type);
69+
#elif PHP_VERSION_ID >= 70300
70+
zend_free_op *should_free;
6971
zval *zv = zend_get_zval_ptr(opline, op_type, node, execute_data, should_free, type);
7072
#else
73+
zend_free_op *should_free;
7174
zval *zv = zend_get_zval_ptr(op_type, node, execute_data, should_free, type);
7275
#endif
7376
ZVAL_DEREF(zv);
@@ -76,17 +79,16 @@ static zval *get_zval_ptr_real(
7679

7780
static zval *get_object_zval_ptr_real(
7881
const zend_op *opline, int op_type, const znode_op *node, zend_execute_data *execute_data,
79-
zend_free_op *should_free, int type
82+
int type
8083
) {
8184
if (op_type == IS_UNUSED) {
8285
if (!SO_THIS) {
8386
zend_error(E_ERROR, "Using $this when not in object context");
8487
}
8588

86-
should_free = NULL;
8789
return SO_THIS;
8890
} else {
89-
return get_zval_ptr_real(opline, op_type, node, execute_data, should_free, type);
91+
return get_zval_ptr_real(opline, op_type, node, execute_data, type);
9092
}
9193
}
9294

@@ -154,6 +156,7 @@ static zend_function *scalar_objects_get_indirection_func(
154156
ind->fn.scope = ce;
155157
ind->fn.fn_flags = ZEND_ACC_CALL_VIA_HANDLER | (fbc->common.fn_flags & keep_flags);
156158
ind->fn.num_args = fbc->common.num_args - 1;
159+
ind->fn.required_num_args = fbc->common.required_num_args - 1;
157160

158161
ind->fbc = fbc;
159162
if (fbc->common.arg_info) {
@@ -172,7 +175,6 @@ static zend_function *scalar_objects_get_indirection_func(
172175
static int scalar_objects_method_call_handler(zend_execute_data *execute_data)
173176
{
174177
const zend_op *opline = execute_data->opline;
175-
zend_free_op free_op1, free_op2;
176178
zval *obj, *method;
177179
zend_class_entry *ce;
178180
zend_function *fbc;
@@ -201,20 +203,16 @@ static int scalar_objects_method_call_handler(zend_execute_data *execute_data)
201203
);
202204
}
203205

204-
method = get_zval_ptr_real(
205-
opline, opline->op2_type, &opline->op2, execute_data, &free_op2, BP_VAR_R
206-
);
207-
obj = get_object_zval_ptr_real(
208-
opline, opline->op1_type, &opline->op1, execute_data, &free_op1, BP_VAR_R
209-
);
206+
method = get_zval_ptr_real(opline, opline->op2_type, &opline->op2, execute_data, BP_VAR_R);
207+
obj = get_object_zval_ptr_real(opline, opline->op1_type, &opline->op1, execute_data, BP_VAR_R);
210208

211209
if (!fbc) {
212210
if (!EG(exception)) {
213211
zend_throw_error(NULL, "Call to undefined method %s::%s()",
214212
ZSTR_VAL(ce->name), Z_STRVAL_P(method));
215213
}
216-
FREE_OP(free_op2);
217-
FREE_OP_IF_VAR(free_op1);
214+
FREE_OP(op2);
215+
FREE_OP(op1);
218216
return ZEND_USER_OPCODE_CONTINUE;
219217
}
220218

@@ -233,8 +231,8 @@ static int scalar_objects_method_call_handler(zend_execute_data *execute_data)
233231
EX(call) = call;
234232
}
235233

236-
FREE_OP(free_op2);
237-
FREE_OP_IF_VAR(free_op1);
234+
FREE_OP(op2);
235+
FREE_OP(op1);
238236

239237
execute_data->opline++;
240238
return ZEND_USER_OPCODE_CONTINUE;

0 commit comments

Comments
 (0)