Coverage Report

Created: 2026-04-01 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/Zend/zend_execute.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Zend Engine                                                          |
4
   +----------------------------------------------------------------------+
5
   | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6
   +----------------------------------------------------------------------+
7
   | This source file is subject to version 2.00 of the Zend license,     |
8
   | that is bundled with this package in the file LICENSE, and is        |
9
   | available through the world-wide-web at the following url:           |
10
   | http://www.zend.com/license/2_00.txt.                                |
11
   | If you did not receive a copy of the Zend license and are unable to  |
12
   | obtain it through the world-wide-web, please send a note to          |
13
   | license@zend.com so we can mail you a copy immediately.              |
14
   +----------------------------------------------------------------------+
15
   | Authors: Andi Gutmans <andi@php.net>                                 |
16
   |          Zeev Suraski <zeev@php.net>                                 |
17
   |          Dmitry Stogov <dmitry@php.net>                              |
18
   +----------------------------------------------------------------------+
19
*/
20
21
#define ZEND_INTENSIVE_DEBUGGING 0
22
23
#include <stdio.h>
24
#include <signal.h>
25
26
#include "zend.h"
27
#include "zend_compile.h"
28
#include "zend_execute.h"
29
#include "zend_API.h"
30
#include "zend_ptr_stack.h"
31
#include "zend_constants.h"
32
#include "zend_extensions.h"
33
#include "zend_ini.h"
34
#include "zend_exceptions.h"
35
#include "zend_interfaces.h"
36
#include "zend_closures.h"
37
#include "zend_generators.h"
38
#include "zend_vm.h"
39
#include "zend_dtrace.h"
40
#include "zend_inheritance.h"
41
#include "zend_type_info.h"
42
#include "zend_smart_str.h"
43
#include "zend_observer.h"
44
#include "zend_system_id.h"
45
#include "zend_call_stack.h"
46
#include "zend_attributes.h"
47
#include "Optimizer/zend_func_info.h"
48
49
/* Virtual current working directory support */
50
#include "zend_virtual_cwd.h"
51
52
#ifdef HAVE_GCC_GLOBAL_REGS
53
# if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386)
54
#  define ZEND_VM_FP_GLOBAL_REG "%esi"
55
#  define ZEND_VM_IP_GLOBAL_REG "%edi"
56
# elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__)
57
#  define ZEND_VM_FP_GLOBAL_REG "%r14"
58
#  define ZEND_VM_IP_GLOBAL_REG "%r15"
59
# elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__)
60
#  define ZEND_VM_FP_GLOBAL_REG "r14"
61
#  define ZEND_VM_IP_GLOBAL_REG "r15"
62
# elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__)
63
#  define ZEND_VM_FP_GLOBAL_REG "r14"
64
#  define ZEND_VM_IP_GLOBAL_REG "r15"
65
# elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__)
66
#  define ZEND_VM_FP_GLOBAL_REG "x27"
67
#  define ZEND_VM_IP_GLOBAL_REG "x28"
68
#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__riscv) && __riscv_xlen == 64
69
#  define ZEND_VM_FP_GLOBAL_REG "x18"
70
#  define ZEND_VM_IP_GLOBAL_REG "x19"
71
# endif
72
#endif
73
74
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
75
# pragma GCC diagnostic ignored "-Wvolatile-register-var"
76
  register zend_execute_data* volatile execute_data __asm__(ZEND_VM_FP_GLOBAL_REG);
77
# pragma GCC diagnostic warning "-Wvolatile-register-var"
78
#endif
79
80
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
81
# define EXECUTE_DATA_D     void
82
# define EXECUTE_DATA_C
83
# define EXECUTE_DATA_DC
84
# define EXECUTE_DATA_CC
85
# define NO_EXECUTE_DATA_CC
86
#else
87
# define EXECUTE_DATA_D     zend_execute_data* execute_data
88
8.72M
# define EXECUTE_DATA_C     execute_data
89
# define EXECUTE_DATA_DC    , EXECUTE_DATA_D
90
7.44M
# define EXECUTE_DATA_CC    , EXECUTE_DATA_C
91
298
# define NO_EXECUTE_DATA_CC , NULL
92
#endif
93
94
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
95
# define OPLINE_D           void
96
# define OPLINE_C
97
# define OPLINE_DC
98
# define OPLINE_CC
99
#else
100
# define OPLINE_D           const zend_op* opline
101
1.55M
# define OPLINE_C           opline
102
# define OPLINE_DC          , OPLINE_D
103
1.55M
# define OPLINE_CC          , OPLINE_C
104
#endif
105
106
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
107
# pragma GCC diagnostic ignored "-Wvolatile-register-var"
108
  register const zend_op* volatile opline __asm__(ZEND_VM_IP_GLOBAL_REG);
109
# pragma GCC diagnostic warning "-Wvolatile-register-var"
110
#else
111
#endif
112
113
52.6M
#define _CONST_CODE  0
114
52.6M
#define _TMP_CODE    1
115
52.6M
#define _VAR_CODE    2
116
263M
#define _UNUSED_CODE 3
117
52.6M
#define _CV_CODE     4
118
119
typedef int (ZEND_FASTCALL *incdec_t)(zval *);
120
121
1.24k
#define get_zval_ptr(op_type, node, type) _get_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
122
70
#define get_zval_ptr_deref(op_type, node, type) _get_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
123
1.86k
#define get_zval_ptr_undef(op_type, node, type) _get_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
124
7.44k
#define get_op_data_zval_ptr_r(op_type, node) _get_op_data_zval_ptr_r(op_type, node EXECUTE_DATA_CC OPLINE_CC)
125
0
#define get_op_data_zval_ptr_deref_r(op_type, node) _get_op_data_zval_ptr_deref_r(op_type, node EXECUTE_DATA_CC OPLINE_CC)
126
218
#define get_zval_ptr_ptr(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC)
127
#define get_zval_ptr_ptr_undef(op_type, node, type) _get_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC)
128
#define get_obj_zval_ptr(op_type, node, type) _get_obj_zval_ptr(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
129
#define get_obj_zval_ptr_deref(op_type, node, type) _get_obj_zval_ptr_deref(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
130
#define get_obj_zval_ptr_undef(op_type, node, type) _get_obj_zval_ptr_undef(op_type, node, type EXECUTE_DATA_CC OPLINE_CC)
131
#define get_obj_zval_ptr_ptr(op_type, node, type) _get_obj_zval_ptr_ptr(op_type, node, type EXECUTE_DATA_CC)
132
133
624k
#define RETURN_VALUE_USED(opline) ((opline)->result_type != IS_UNUSED)
134
135
static ZEND_FUNCTION(pass)
136
255
{
137
255
}
138
139
static zend_arg_info zend_pass_function_arg_info[1] = {0};
140
141
ZEND_API const zend_internal_function zend_pass_function = {
142
  ZEND_INTERNAL_FUNCTION, /* type              */
143
  {0, 0, 0},              /* arg_flags         */
144
  0,                      /* fn_flags          */
145
  NULL,                   /* name              */
146
  NULL,                   /* scope             */
147
  NULL,                   /* prototype         */
148
  0,                      /* num_args          */
149
  0,                      /* required_num_args */
150
  zend_pass_function_arg_info + 1, /* arg_info */
151
  NULL,                   /* attributes        */
152
  NULL,                   /* run_time_cache    */
153
  NULL,                   /* doc_comment       */
154
  0,                      /* T                 */
155
  0,                      /* fn_flags2         */
156
  NULL,                   /* prop_info */
157
  ZEND_FN(pass),          /* handler           */
158
  NULL,                   /* module            */
159
  NULL,                   /* frameless_function_infos */
160
  {NULL,NULL,NULL,NULL}   /* reserved          */
161
};
162
163
3.63k
#define FREE_VAR_PTR_AND_EXTRACT_RESULT_IF_NECESSARY(free_var) do {     \
164
3.63k
  zval *__container_to_free = EX_VAR(free_var);             \
165
3.63k
  if (UNEXPECTED(Z_REFCOUNTED_P(__container_to_free))) {         \
166
402
    zend_refcounted *__ref = Z_COUNTED_P(__container_to_free);      \
167
402
    if (UNEXPECTED(!GC_DELREF(__ref))) {               \
168
264
      zval *__zv = EX_VAR(opline->result.var);           \
169
264
      if (EXPECTED(Z_TYPE_P(__zv) == IS_INDIRECT)) {         \
170
260
        ZVAL_COPY(__zv, Z_INDIRECT_P(__zv));           \
171
260
      }                                \
172
264
      rc_dtor_func(__ref);                      \
173
264
    }                                  \
174
402
  }                                    \
175
3.63k
} while (0)
176
177
#define FREE_OP(type, var) \
178
17.7k
  if ((type) & (IS_TMP_VAR|IS_VAR)) { \
179
7.22k
    zval_ptr_dtor_nogc(EX_VAR(var)); \
180
7.22k
  }
181
182
1.35M
#define CV_DEF_OF(i) (EX(func)->op_array.vars[i])
183
184
449k
#define ZEND_VM_STACK_PAGE_SLOTS (16 * 1024) /* should be a power of 2 */
185
186
449k
#define ZEND_VM_STACK_PAGE_SIZE  (ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval))
187
188
#define ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, page_size) \
189
58
  (((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \
190
58
    + ((page_size) - 1)) & ~((page_size) - 1))
191
192
ZEND_API void zend_vm_stack_init(void)
193
224k
{
194
224k
  EG(vm_stack_page_size) = ZEND_VM_STACK_PAGE_SIZE;
195
224k
  EG(vm_stack) = zend_vm_stack_new_page(ZEND_VM_STACK_PAGE_SIZE, NULL);
196
224k
  EG(vm_stack_top) = EG(vm_stack)->top;
197
224k
  EG(vm_stack_end) = EG(vm_stack)->end;
198
224k
}
199
200
ZEND_API void zend_vm_stack_init_ex(size_t page_size)
201
0
{
202
  /* page_size must be a power of 2 */
203
0
  ZEND_ASSERT(page_size > 0 && (page_size & (page_size - 1)) == 0);
204
0
  EG(vm_stack_page_size) = page_size;
205
0
  EG(vm_stack) = zend_vm_stack_new_page(page_size, NULL);
206
0
  EG(vm_stack_top) = EG(vm_stack)->top;
207
0
  EG(vm_stack_end) = EG(vm_stack)->end;
208
0
}
209
210
ZEND_API void zend_vm_stack_destroy(void)
211
225k
{
212
225k
  zend_vm_stack stack = EG(vm_stack);
213
214
451k
  while (stack != NULL) {
215
225k
    zend_vm_stack p = stack->prev;
216
225k
    efree(stack);
217
225k
    stack = p;
218
225k
  }
219
225k
}
220
221
ZEND_API void* zend_vm_stack_extend(size_t size)
222
70
{
223
70
  zend_vm_stack stack;
224
70
  void *ptr;
225
226
70
  stack = EG(vm_stack);
227
70
  stack->top = EG(vm_stack_top);
228
70
  EG(vm_stack) = stack = zend_vm_stack_new_page(
229
70
    EXPECTED(size < EG(vm_stack_page_size) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval))) ?
230
58
      EG(vm_stack_page_size) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE(size, EG(vm_stack_page_size)),
231
70
    stack);
232
70
  ptr = stack->top;
233
70
  EG(vm_stack_top) = (void*)(((char*)ptr) + size);
234
70
  EG(vm_stack_end) = stack->end;
235
70
  return ptr;
236
70
}
237
238
ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute_data, uint32_t var)
239
0
{
240
0
  return EX_VAR(var);
241
0
}
242
243
ZEND_API bool zend_gcc_global_regs(void)
244
0
{
245
  #if defined(HAVE_GCC_GLOBAL_REGS)
246
        return 1;
247
  #else
248
0
        return 0;
249
0
  #endif
250
0
}
251
252
static zend_always_inline zval *_get_zval_ptr_tmp(uint32_t var EXECUTE_DATA_DC)
253
3.45M
{
254
3.45M
  zval *ret = EX_VAR(var);
255
256
3.45M
  ZEND_ASSERT(Z_TYPE_P(ret) != IS_REFERENCE);
257
258
3.45M
  return ret;
259
3.45M
}
260
261
static zend_always_inline zval *_get_zval_ptr_var(uint32_t var EXECUTE_DATA_DC)
262
313k
{
263
313k
  zval *ret = EX_VAR(var);
264
265
313k
  return ret;
266
313k
}
267
268
static zend_always_inline zval *_get_zval_ptr_var_deref(uint32_t var EXECUTE_DATA_DC)
269
0
{
270
0
  zval *ret = EX_VAR(var);
271
272
0
  ZVAL_DEREF(ret);
273
0
  return ret;
274
0
}
275
276
static zend_never_inline ZEND_COLD zval* zval_undefined_cv(uint32_t var EXECUTE_DATA_DC)
277
1.35M
{
278
1.35M
  if (EXPECTED(EG(exception) == NULL)) {
279
1.35M
    zend_string *cv = CV_DEF_OF(EX_VAR_TO_NUM(var));
280
1.35M
    zend_error_unchecked(E_WARNING, "Undefined variable $%S", cv);
281
1.35M
  }
282
1.35M
  return &EG(uninitialized_zval);
283
1.35M
}
284
285
static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op1(EXECUTE_DATA_D)
286
756k
{
287
756k
  return zval_undefined_cv(EX(opline)->op1.var EXECUTE_DATA_CC);
288
756k
}
289
290
static zend_never_inline ZEND_COLD zval* ZEND_FASTCALL _zval_undefined_op2(EXECUTE_DATA_D)
291
504k
{
292
504k
  return zval_undefined_cv(EX(opline)->op2.var EXECUTE_DATA_CC);
293
504k
}
294
295
756k
#define ZVAL_UNDEFINED_OP1() _zval_undefined_op1(EXECUTE_DATA_C)
296
504k
#define ZVAL_UNDEFINED_OP2() _zval_undefined_op2(EXECUTE_DATA_C)
297
298
static zend_never_inline ZEND_COLD zval *_get_zval_cv_lookup(zval *ptr, uint32_t var, int type EXECUTE_DATA_DC)
299
134
{
300
134
  switch (type) {
301
134
    case BP_VAR_R:
302
134
    case BP_VAR_UNSET:
303
134
      ptr = zval_undefined_cv(var EXECUTE_DATA_CC);
304
134
      break;
305
0
    case BP_VAR_IS:
306
0
      ptr = &EG(uninitialized_zval);
307
0
      break;
308
0
    case BP_VAR_RW:
309
0
      zval_undefined_cv(var EXECUTE_DATA_CC);
310
0
      ZEND_FALLTHROUGH;
311
0
    case BP_VAR_W:
312
0
      ZVAL_NULL(ptr);
313
0
      break;
314
134
  }
315
134
  return ptr;
316
134
}
317
318
static zend_always_inline zval *_get_zval_ptr_cv(uint32_t var, int type EXECUTE_DATA_DC)
319
884
{
320
884
  zval *ret = EX_VAR(var);
321
322
884
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
323
45
    if (type == BP_VAR_W) {
324
18
      ZVAL_NULL(ret);
325
27
    } else {
326
27
      return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC);
327
27
    }
328
45
  }
329
857
  return ret;
330
884
}
331
332
static zend_always_inline zval *_get_zval_ptr_cv_deref(uint32_t var, int type EXECUTE_DATA_DC)
333
439
{
334
439
  zval *ret = EX_VAR(var);
335
336
439
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
337
107
    if (type == BP_VAR_W) {
338
0
      ZVAL_NULL(ret);
339
0
      return ret;
340
107
    } else {
341
107
      return _get_zval_cv_lookup(ret, var, type EXECUTE_DATA_CC);
342
107
    }
343
107
  }
344
332
  ZVAL_DEREF(ret);
345
332
  return ret;
346
439
}
347
348
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_R(uint32_t var EXECUTE_DATA_DC)
349
101k
{
350
101k
  zval *ret = EX_VAR(var);
351
352
101k
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
353
12.9k
    return zval_undefined_cv(var EXECUTE_DATA_CC);
354
12.9k
  }
355
88.5k
  return ret;
356
101k
}
357
358
static zend_always_inline zval *_get_zval_ptr_cv_deref_BP_VAR_R(uint32_t var EXECUTE_DATA_DC)
359
28.5k
{
360
28.5k
  zval *ret = EX_VAR(var);
361
362
28.5k
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
363
2.86k
    return zval_undefined_cv(var EXECUTE_DATA_CC);
364
2.86k
  }
365
25.6k
  ZVAL_DEREF(ret);
366
25.6k
  return ret;
367
28.5k
}
368
369
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_IS(uint32_t var EXECUTE_DATA_DC)
370
1.59k
{
371
1.59k
  zval *ret = EX_VAR(var);
372
373
1.59k
  return ret;
374
1.59k
}
375
376
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_RW(uint32_t var EXECUTE_DATA_DC)
377
1.41M
{
378
1.41M
  zval *ret = EX_VAR(var);
379
380
1.41M
  if (UNEXPECTED(Z_TYPE_P(ret) == IS_UNDEF)) {
381
78.5k
    zval_undefined_cv(var EXECUTE_DATA_CC);
382
78.5k
    ZVAL_NULL(ret);
383
78.5k
    return ret;
384
78.5k
  }
385
1.33M
  return ret;
386
1.41M
}
387
388
static zend_always_inline zval *_get_zval_ptr_cv_BP_VAR_W(uint32_t var EXECUTE_DATA_DC)
389
22.5k
{
390
22.5k
  zval *ret = EX_VAR(var);
391
392
22.5k
  if (Z_TYPE_P(ret) == IS_UNDEF) {
393
1.43k
    ZVAL_NULL(ret);
394
1.43k
  }
395
22.5k
  return ret;
396
22.5k
}
397
398
static zend_always_inline zval *_get_zval_ptr_tmpvarcv(int op_type, znode_op node, int type EXECUTE_DATA_DC)
399
501
{
400
501
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
401
149
    if (op_type == IS_TMP_VAR) {
402
149
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
403
149
    } else {
404
0
      ZEND_ASSERT(op_type == IS_VAR);
405
0
      return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
406
0
    }
407
352
  } else {
408
352
    ZEND_ASSERT(op_type == IS_CV);
409
352
    return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC);
410
352
  }
411
501
}
412
413
static zend_always_inline zval *_get_zval_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC)
414
1.24k
{
415
1.24k
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
416
252
    if (!ZEND_DEBUG || op_type == IS_VAR) {
417
0
      return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
418
252
    } else {
419
252
      ZEND_ASSERT(op_type == IS_TMP_VAR);
420
252
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
421
252
    }
422
994
  } else {
423
994
    if (op_type == IS_CONST) {
424
168
      return RT_CONSTANT(opline, node);
425
826
    } else if (op_type == IS_CV) {
426
826
      return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC);
427
826
    } else {
428
0
      return NULL;
429
0
    }
430
994
  }
431
1.24k
}
432
433
static zend_always_inline zval *_get_op_data_zval_ptr_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC)
434
7.63k
{
435
7.63k
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
436
1.16k
    if (!ZEND_DEBUG || op_type == IS_VAR) {
437
0
      return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
438
1.16k
    } else {
439
1.16k
      ZEND_ASSERT(op_type == IS_TMP_VAR);
440
1.16k
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
441
1.16k
    }
442
6.47k
  } else {
443
6.47k
    if (op_type == IS_CONST) {
444
5.36k
      return RT_CONSTANT(opline + 1, node);
445
5.36k
    } else if (op_type == IS_CV) {
446
1.10k
      return _get_zval_ptr_cv_BP_VAR_R(node.var EXECUTE_DATA_CC);
447
1.10k
    } else {
448
0
      return NULL;
449
0
    }
450
6.47k
  }
451
7.63k
}
452
453
static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_zval_ptr_deref(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC)
454
293
{
455
293
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
456
201
    if (op_type == IS_TMP_VAR) {
457
201
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
458
201
    } else {
459
0
      ZEND_ASSERT(op_type == IS_VAR);
460
0
      return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
461
0
    }
462
201
  } else {
463
92
    if (op_type == IS_CONST) {
464
5
      return RT_CONSTANT(opline, node);
465
87
    } else if (op_type == IS_CV) {
466
87
      return _get_zval_ptr_cv_deref(node.var, type EXECUTE_DATA_CC);
467
87
    } else {
468
0
      return NULL;
469
0
    }
470
92
  }
471
293
}
472
473
static zend_always_inline ZEND_ATTRIBUTE_UNUSED zval *_get_op_data_zval_ptr_deref_r(int op_type, znode_op node EXECUTE_DATA_DC OPLINE_DC)
474
0
{
475
0
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
476
0
    if (op_type == IS_TMP_VAR) {
477
0
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
478
0
    } else {
479
0
      ZEND_ASSERT(op_type == IS_VAR);
480
0
      return _get_zval_ptr_var_deref(node.var EXECUTE_DATA_CC);
481
0
    }
482
0
  } else {
483
0
    if (op_type == IS_CONST) {
484
0
      return RT_CONSTANT(opline + 1, node);
485
0
    } else if (op_type == IS_CV) {
486
0
      return _get_zval_ptr_cv_deref_BP_VAR_R(node.var EXECUTE_DATA_CC);
487
0
    } else {
488
0
      return NULL;
489
0
    }
490
0
  }
491
0
}
492
493
static zend_always_inline zval *_get_zval_ptr_undef(int op_type, znode_op node, int type EXECUTE_DATA_DC OPLINE_DC)
494
1.86k
{
495
1.86k
  if (op_type & (IS_TMP_VAR|IS_VAR)) {
496
314
    if (!ZEND_DEBUG || op_type == IS_VAR) {
497
0
      return _get_zval_ptr_var(node.var EXECUTE_DATA_CC);
498
314
    } else {
499
314
      ZEND_ASSERT(op_type == IS_TMP_VAR);
500
314
      return _get_zval_ptr_tmp(node.var EXECUTE_DATA_CC);
501
314
    }
502
1.55k
  } else {
503
1.55k
    if (op_type == IS_CONST) {
504
345
      return RT_CONSTANT(opline, node);
505
1.20k
    } else if (op_type == IS_CV) {
506
1.20k
      return EX_VAR(node.var);
507
1.20k
    } else {
508
0
      return NULL;
509
0
    }
510
1.55k
  }
511
1.86k
}
512
513
static zend_always_inline zval *_get_zval_ptr_ptr_var(uint32_t var EXECUTE_DATA_DC)
514
68.4k
{
515
68.4k
  zval *ret = EX_VAR(var);
516
517
68.4k
  if (EXPECTED(Z_TYPE_P(ret) == IS_INDIRECT)) {
518
61.8k
    ret = Z_INDIRECT_P(ret);
519
61.8k
  }
520
68.4k
  return ret;
521
68.4k
}
522
523
static inline zval *_get_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC)
524
218
{
525
218
  if (op_type == IS_CV) {
526
58
    return _get_zval_ptr_cv(node.var, type EXECUTE_DATA_CC);
527
160
  } else /* if (op_type == IS_VAR) */ {
528
160
    ZEND_ASSERT(op_type == IS_VAR);
529
160
    return _get_zval_ptr_ptr_var(node.var EXECUTE_DATA_CC);
530
160
  }
531
218
}
532
533
static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC)
534
0
{
535
0
  if (op_type == IS_UNUSED) {
536
0
    return &EX(This);
537
0
  }
538
0
  return get_zval_ptr(op_type, op, type);
539
0
}
540
541
static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_deref(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC)
542
0
{
543
0
  if (op_type == IS_UNUSED) {
544
0
    return &EX(This);
545
0
  }
546
0
  return get_zval_ptr_deref(op_type, op, type);
547
0
}
548
549
static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_undef(int op_type, znode_op op, int type EXECUTE_DATA_DC OPLINE_DC)
550
0
{
551
0
  if (op_type == IS_UNUSED) {
552
0
    return &EX(This);
553
0
  }
554
0
  return get_zval_ptr_undef(op_type, op, type);
555
0
}
556
557
static inline ZEND_ATTRIBUTE_UNUSED zval *_get_obj_zval_ptr_ptr(int op_type, znode_op node, int type EXECUTE_DATA_DC)
558
0
{
559
0
  if (op_type == IS_UNUSED) {
560
0
    return &EX(This);
561
0
  }
562
0
  return get_zval_ptr_ptr(op_type, node, type);
563
0
}
564
565
static inline void zend_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr, zend_refcounted **garbage_ptr)
566
20.0k
{
567
20.0k
  zend_reference *ref;
568
569
20.0k
  if (EXPECTED(!Z_ISREF_P(value_ptr))) {
570
6.90k
    ZVAL_NEW_REF(value_ptr, value_ptr);
571
13.1k
  } else if (UNEXPECTED(variable_ptr == value_ptr)) {
572
2.61k
    return;
573
2.61k
  }
574
575
17.4k
  ref = Z_REF_P(value_ptr);
576
17.4k
  GC_ADDREF(ref);
577
17.4k
  if (Z_REFCOUNTED_P(variable_ptr)) {
578
7.29k
    *garbage_ptr = Z_COUNTED_P(variable_ptr);
579
7.29k
  }
580
17.4k
  ZVAL_REF(variable_ptr, ref);
581
17.4k
}
582
583
static zend_never_inline zval* zend_assign_to_typed_property_reference(zend_property_info *prop_info, zval *prop, zval *value_ptr, zend_refcounted **garbage_ptr EXECUTE_DATA_DC)
584
716
{
585
716
  if (!zend_verify_prop_assignable_by_ref(prop_info, value_ptr, EX_USES_STRICT_TYPES())) {
586
143
    return &EG(uninitialized_zval);
587
143
  }
588
573
  if (Z_ISREF_P(prop)) {
589
272
    ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(prop), prop_info);
590
272
  }
591
573
  zend_assign_to_variable_reference(prop, value_ptr, garbage_ptr);
592
573
  ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(prop), prop_info);
593
573
  return prop;
594
716
}
595
596
static zend_never_inline ZEND_COLD zval *zend_wrong_assign_to_variable_reference(zval *variable_ptr, zval *value_ptr, zend_refcounted **garbage_ptr OPLINE_DC EXECUTE_DATA_DC)
597
139
{
598
139
  zend_error(E_NOTICE, "Only variables should be assigned by reference");
599
139
  if (UNEXPECTED(EG(exception) != NULL)) {
600
0
    return &EG(uninitialized_zval);
601
0
  }
602
603
  /* Use IS_TMP_VAR instead of IS_VAR to avoid ISREF check */
604
139
  Z_TRY_ADDREF_P(value_ptr);
605
139
  return zend_assign_to_variable_ex(variable_ptr, value_ptr, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr);
606
139
}
607
608
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_pass_by_reference(uint32_t arg_num)
609
114
{
610
114
  const zend_execute_data *execute_data = EG(current_execute_data);
611
114
  zend_string *func_name = get_function_or_method_name(EX(call)->func);
612
114
  const char *param_name = get_function_arg_name(EX(call)->func, arg_num);
613
614
114
  zend_throw_error(NULL, "%s(): Argument #%d%s%s%s could not be passed by reference",
615
114
    ZSTR_VAL(func_name), arg_num, param_name ? " ($" : "", param_name ? param_name : "", param_name ? ")" : ""
616
114
  );
617
618
114
  zend_string_release(func_name);
619
114
}
620
621
15
static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(const zend_property_info *prop) {
622
15
  zend_string *type_str = zend_type_to_string(prop->type);
623
15
  zend_type_error(
624
15
    "Cannot auto-initialize an array inside property %s::$%s of type %s",
625
15
    ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
626
15
    ZSTR_VAL(type_str)
627
15
  );
628
15
  zend_string_release(type_str);
629
15
}
630
631
10
static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_ref_error(const zend_property_info *prop) {
632
10
  zend_string *type_str = zend_type_to_string(prop->type);
633
10
  zend_type_error(
634
10
    "Cannot auto-initialize an array inside a reference held by property %s::$%s of type %s",
635
10
    ZSTR_VAL(prop->ce->name), zend_get_unmangled_property_name(prop->name),
636
10
    ZSTR_VAL(type_str)
637
10
  );
638
10
  zend_string_release(type_str);
639
10
}
640
641
static zend_never_inline ZEND_COLD void zend_throw_access_uninit_prop_by_ref_error(
642
23
    const zend_property_info *prop) {
643
23
  zend_throw_error(NULL,
644
23
    "Cannot access uninitialized non-nullable property %s::$%s by reference",
645
23
    ZSTR_VAL(prop->ce->name),
646
23
    zend_get_unmangled_property_name(prop->name));
647
23
}
648
649
/* this should modify object only if it's empty */
650
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_error(const zval *object, zval *property OPLINE_DC EXECUTE_DATA_DC)
651
1.05k
{
652
1.05k
  zend_string *tmp_property_name;
653
1.05k
  zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
654
655
1.05k
  if (opline->opcode == ZEND_PRE_INC_OBJ
656
1.01k
   || opline->opcode == ZEND_PRE_DEC_OBJ
657
999
   || opline->opcode == ZEND_POST_INC_OBJ
658
970
   || opline->opcode == ZEND_POST_DEC_OBJ) {
659
85
    zend_throw_error(NULL,
660
85
      "Attempt to increment/decrement property \"%s\" on %s",
661
85
      ZSTR_VAL(property_name), zend_zval_value_name(object)
662
85
    );
663
967
  } else if (opline->opcode == ZEND_FETCH_OBJ_W
664
856
      || opline->opcode == ZEND_FETCH_OBJ_RW
665
829
      || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG
666
829
      || opline->opcode == ZEND_ASSIGN_OBJ_REF) {
667
180
    zend_throw_error(NULL,
668
180
      "Attempt to modify property \"%s\" on %s",
669
180
      ZSTR_VAL(property_name), zend_zval_value_name(object)
670
180
    );
671
787
  } else {
672
787
    zend_throw_error(NULL,
673
787
      "Attempt to assign property \"%s\" on %s",
674
787
      ZSTR_VAL(property_name), zend_zval_value_name(object)
675
787
    );
676
787
  }
677
1.05k
  zend_tmp_string_release(tmp_property_name);
678
679
1.05k
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
680
698
    ZVAL_NULL(EX_VAR(opline->result.var));
681
698
  }
682
1.05k
}
683
684
static ZEND_COLD void zend_verify_type_error_common(
685
    const zend_function *zf, const zend_arg_info *arg_info, const zval *value,
686
    const char **fname, const char **fsep, const char **fclass,
687
    zend_string **need_msg, const char **given_kind)
688
992
{
689
992
  *fname = ZSTR_VAL(zf->common.function_name);
690
992
  if (zf->common.scope) {
691
289
    *fsep =  "::";
692
289
    *fclass = ZSTR_VAL(zf->common.scope->name);
693
703
  } else {
694
703
    *fsep =  "";
695
703
    *fclass = "";
696
703
  }
697
698
992
  *need_msg = zend_type_to_string_resolved(arg_info->type, zf->common.scope);
699
700
992
  if (value) {
701
918
    *given_kind = zend_zval_value_name(value);
702
918
  } else {
703
74
    *given_kind = "none";
704
74
  }
705
992
}
706
707
ZEND_API ZEND_COLD void zend_verify_arg_error(
708
    const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, const zval *value)
709
657
{
710
657
  const zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
711
657
  const char *fname, *fsep, *fclass;
712
657
  zend_string *need_msg;
713
657
  const char *given_msg;
714
715
657
  zend_verify_type_error_common(
716
657
    zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);
717
718
657
  ZEND_ASSERT(zf->common.type == ZEND_USER_FUNCTION
719
657
    && "Arginfo verification is not performed for internal functions");
720
657
  if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
721
628
    zend_argument_type_error(arg_num, "must be of type %s, %s given, called in %s on line %d",
722
628
      ZSTR_VAL(need_msg), given_msg,
723
628
      ZSTR_VAL(ptr->func->op_array.filename), ptr->opline->lineno
724
628
    );
725
628
  } else {
726
29
    zend_argument_type_error(arg_num,
727
29
      "must be of type %s, %s given", ZSTR_VAL(need_msg), given_msg);
728
29
  }
729
730
657
  zend_string_release(need_msg);
731
657
}
732
733
static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
734
2.59k
{
735
2.59k
  zend_long lval;
736
2.59k
  double dval;
737
2.59k
  zend_string *str;
738
2.59k
  bool bval;
739
740
  /* Type preference order: int -> float -> string -> bool */
741
2.59k
  if (type_mask & MAY_BE_LONG) {
742
    /* For an int|float union type and string value,
743
     * determine chosen type by is_numeric_string() semantics. */
744
1.09k
    if ((type_mask & MAY_BE_DOUBLE) && Z_TYPE_P(arg) == IS_STRING) {
745
45
      uint8_t type = is_numeric_str_function(Z_STR_P(arg), &lval, &dval);
746
45
      if (type == IS_LONG) {
747
8
        zend_string_release(Z_STR_P(arg));
748
8
        ZVAL_LONG(arg, lval);
749
8
        return true;
750
8
      }
751
37
      if (type == IS_DOUBLE) {
752
12
        zend_string_release(Z_STR_P(arg));
753
12
        ZVAL_DOUBLE(arg, dval);
754
12
        return true;
755
12
      }
756
1.05k
    } else if (zend_parse_arg_long_weak(arg, &lval, 0)) {
757
597
      zval_ptr_dtor(arg);
758
597
      ZVAL_LONG(arg, lval);
759
597
      return true;
760
597
    } else if (UNEXPECTED(EG(exception))) {
761
0
      return false;
762
0
    }
763
1.09k
  }
764
1.97k
  if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) {
765
139
    zval_ptr_dtor(arg);
766
139
    ZVAL_DOUBLE(arg, dval);
767
139
    return true;
768
139
  }
769
1.83k
  if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(arg, &str, 0)) {
770
    /* on success "arg" is converted to IS_STRING */
771
489
    return true;
772
489
  }
773
1.34k
  if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) {
774
49
    zval_ptr_dtor(arg);
775
49
    ZVAL_BOOL(arg, bval);
776
49
    return true;
777
49
  }
778
1.29k
  return false;
779
1.34k
}
780
781
#if ZEND_DEBUG
782
3.99k
static bool can_convert_to_string(const zval *zv) {
783
  /* We don't call cast_object here, because this check must be side-effect free. As this
784
   * is only used for a sanity check of arginfo/zpp consistency, it's okay if we accept
785
   * more than actually allowed here. */
786
3.99k
  if (Z_TYPE_P(zv) == IS_OBJECT) {
787
898
    return Z_OBJ_HT_P(zv)->cast_object != zend_std_cast_object_tostring
788
898
      || Z_OBJCE_P(zv)->__tostring;
789
898
  }
790
3.09k
  return Z_TYPE_P(zv) <= IS_STRING;
791
3.99k
}
792
793
/* Used to sanity-check internal arginfo types without performing any actual type conversions. */
794
static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask, const zval *arg)
795
6.36k
{
796
6.36k
  zend_long lval;
797
6.36k
  double dval;
798
6.36k
  bool bval;
799
800
  /* Pass (uint32_t)-1 as arg_num to indicate to ZPP not to emit any deprecation notice,
801
   * this is needed because the version with side effects also uses 0 (e.g. for typed properties) */
802
6.36k
  if ((type_mask & MAY_BE_LONG) && zend_parse_arg_long_weak(arg, &lval, (uint32_t)-1)) {
803
374
    return true;
804
374
  }
805
5.98k
  if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, (uint32_t)-1)) {
806
547
    return true;
807
547
  }
808
5.44k
  if ((type_mask & MAY_BE_STRING) && can_convert_to_string(arg)) {
809
3.94k
    return true;
810
3.94k
  }
811
1.50k
  if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, (uint32_t)-1)) {
812
1.15k
    return true;
813
1.15k
  }
814
345
  return false;
815
1.50k
}
816
#endif
817
818
ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool strict, bool is_internal_arg)
819
14.4k
{
820
14.4k
  if (UNEXPECTED(strict)) {
821
    /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */
822
243
    if (!(type_mask & MAY_BE_DOUBLE) || Z_TYPE_P(arg) != IS_LONG) {
823
237
      return 0;
824
237
    }
825
14.1k
  } else if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
826
    /* NULL may be accepted only by nullable hints (this is already checked).
827
     * As an exception for internal functions, null is allowed for scalar types in weak mode. */
828
5.53k
    return is_internal_arg
829
5.35k
      && (type_mask & (MAY_BE_TRUE|MAY_BE_FALSE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING));
830
5.53k
  }
831
8.65k
#if ZEND_DEBUG
832
8.65k
  if (is_internal_arg) {
833
6.36k
    return zend_verify_weak_scalar_type_hint_no_sideeffect(type_mask, arg);
834
6.36k
  }
835
2.28k
#endif
836
2.28k
  return zend_verify_weak_scalar_type_hint(type_mask, arg);
837
8.65k
}
838
839
ZEND_COLD zend_never_inline void zend_verify_class_constant_type_error(const zend_class_constant *c, const zend_string *name, const zval *constant)
840
65
{
841
65
  zend_string *type_str = zend_type_to_string(c->type);
842
843
65
  zend_type_error("Cannot assign %s to class constant %s::%s of type %s",
844
65
    zend_zval_type_name(constant), ZSTR_VAL(c->ce->name), ZSTR_VAL(name), ZSTR_VAL(type_str));
845
846
65
  zend_string_release(type_str);
847
65
}
848
849
ZEND_COLD zend_never_inline void zend_verify_property_type_error(const zend_property_info *info, const zval *property)
850
629
{
851
629
  zend_string *type_str;
852
853
  /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */
854
629
  if (EG(exception)) {
855
20
    return;
856
20
  }
857
858
609
  type_str = zend_type_to_string(info->type);
859
609
  zend_type_error("Cannot assign %s to property %s::$%s of type %s",
860
609
    zend_zval_value_name(property),
861
609
    ZSTR_VAL(info->ce->name),
862
609
    zend_get_unmangled_property_name(info->name),
863
609
    ZSTR_VAL(type_str));
864
609
  zend_string_release(type_str);
865
609
}
866
867
ZEND_COLD zend_never_inline void zend_magic_get_property_type_inconsistency_error(const zend_property_info *info, const zval *property)
868
16
{
869
  /* we _may_ land here in case reading already errored and runtime cache thus has not been updated (i.e. it contains a valid but unrelated info) */
870
16
  if (EG(exception)) {
871
0
    return;
872
0
  }
873
874
16
  zend_string *type_str = zend_type_to_string(info->type);
875
16
  zend_type_error("Value of type %s returned from %s::__get() must be compatible with unset property %s::$%s of type %s",
876
16
    zend_zval_type_name(property),
877
16
    ZSTR_VAL(info->ce->name),
878
16
    ZSTR_VAL(info->ce->name),
879
16
    zend_get_unmangled_property_name(info->name),
880
16
    ZSTR_VAL(type_str));
881
16
  zend_string_release(type_str);
882
16
}
883
884
ZEND_COLD void zend_match_unhandled_error(const zval *value)
885
150
{
886
150
  zend_long max_len = EG(exception_string_param_max_len);
887
150
  smart_str msg = {0};
888
150
  if (
889
150
    EG(exception_ignore_args)
890
150
    || (Z_TYPE_P(value) == IS_STRING && max_len == 0)
891
150
    || smart_str_append_zval(&msg, value, max_len) != SUCCESS
892
150
  ) {
893
10
    smart_str_appendl(&msg, "of type ", sizeof("of type ")-1);
894
10
    smart_str_appends(&msg, zend_zval_type_name(value));
895
10
  }
896
150
  smart_str_0(&msg);
897
898
150
  zend_throw_exception_ex(
899
150
    zend_ce_unhandled_match_error, 0, "Unhandled match case %s", ZSTR_VAL(msg.s));
900
901
150
  smart_str_free(&msg);
902
150
}
903
904
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(
905
237
    const zend_property_info *info) {
906
237
  zend_readonly_property_modification_error_ex(
907
237
    ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
908
237
}
909
910
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(
911
237
    const char *class_name, const char *prop_name) {
912
237
  zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", class_name, prop_name);
913
237
}
914
915
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info)
916
139
{
917
139
  zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s",
918
139
    ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
919
139
}
920
921
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_invalid_class_constant_type_error(const uint8_t type)
922
269
{
923
269
  zend_type_error("Cannot use value of type %s as class constant name", zend_get_type_by_const(type));
924
269
}
925
926
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_object_released_while_assigning_to_property_error(const zend_property_info *info)
927
18
{
928
18
  zend_throw_error(NULL, "Object was released while assigning to property %s::$%s",
929
18
    ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
930
18
}
931
932
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modification_error(
933
  const zend_property_info *prop_info, const char *operation
934
420
) {
935
420
  const zend_class_entry *scope;
936
420
  if (EG(fake_scope)) {
937
8
    scope = EG(fake_scope);
938
412
  } else {
939
412
    scope = zend_get_called_scope(EG(current_execute_data));
940
412
  }
941
942
420
  const char *visibility;
943
420
  if (prop_info->flags & ZEND_ACC_PRIVATE_SET) {
944
355
    visibility = "private(set)";
945
355
  } else {
946
65
    ZEND_ASSERT(prop_info->flags & ZEND_ACC_PROTECTED_SET);
947
65
    if (prop_info->flags & ZEND_ACC_READONLY) {
948
42
      visibility = "protected(set) readonly";
949
42
    } else {
950
23
      visibility = "protected(set)";
951
23
    }
952
65
  }
953
954
420
  zend_throw_error(NULL, "Cannot %s %s property %s::$%s from %s%s",
955
420
    operation,
956
420
    visibility,
957
420
    ZSTR_VAL(prop_info->ce->name),
958
420
    ZSTR_VAL(prop_info->name),
959
420
    scope ? "scope " : "global scope", scope ? ZSTR_VAL(scope->name) : "");
960
420
}
961
962
106
static const zend_class_entry *resolve_single_class_type(zend_string *name, const zend_class_entry *self_ce) {
963
106
  if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) {
964
23
    return self_ce;
965
83
  } else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
966
13
    return self_ce->parent;
967
70
  } else {
968
70
    return zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
969
70
  }
970
106
}
971
972
static zend_always_inline const zend_class_entry *zend_ce_from_type(
973
229k
    const zend_class_entry *scope, const zend_type *type) {
974
229k
  ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type));
975
229k
  zend_string *name = ZEND_TYPE_NAME(*type);
976
229k
  if (ZSTR_HAS_CE_CACHE(name)) {
977
229k
    zend_class_entry *ce = ZSTR_GET_CE_CACHE(name);
978
229k
    if (!ce) {
979
2.16k
      ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
980
2.16k
    }
981
229k
    return ce;
982
229k
  }
983
106
  return resolve_single_class_type(name, scope);
984
229k
}
985
986
static bool zend_check_intersection_for_property_or_class_constant_class_type(
987
  const zend_class_entry *scope, const zend_type_list *intersection_type_list, const zend_class_entry *value_ce)
988
203
{
989
203
  const zend_type *list_type;
990
991
593
  ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
992
593
    ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
993
593
    const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
994
390
    if (!ce || !instanceof_function(value_ce, ce)) {
995
93
      return false;
996
93
    }
997
390
  } ZEND_TYPE_LIST_FOREACH_END();
998
110
  return true;
999
203
}
1000
1001
static bool zend_check_and_resolve_property_or_class_constant_class_type(
1002
228k
  const zend_class_entry *scope, const zend_type member_type, const zend_class_entry *value_ce) {
1003
228k
  if (ZEND_TYPE_HAS_LIST(member_type)) {
1004
271
    if (ZEND_TYPE_IS_INTERSECTION(member_type)) {
1005
105
      return zend_check_intersection_for_property_or_class_constant_class_type(
1006
105
        scope, ZEND_TYPE_LIST(member_type), value_ce);
1007
166
    } else {
1008
166
      const zend_type *list_type;
1009
400
      ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(member_type), list_type) {
1010
400
        if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
1011
98
          if (zend_check_intersection_for_property_or_class_constant_class_type(
1012
98
              scope, ZEND_TYPE_LIST(*list_type), value_ce)) {
1013
60
            return true;
1014
60
          }
1015
38
          continue;
1016
98
        }
1017
136
        ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
1018
136
        const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
1019
136
        if (ce && instanceof_function(value_ce, ce)) {
1020
58
          return true;
1021
58
        }
1022
136
      } ZEND_TYPE_LIST_FOREACH_END();
1023
1024
48
      if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC)) {
1025
0
        return value_ce == scope;
1026
0
      }
1027
1028
48
      return false;
1029
48
    }
1030
228k
  } else if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC) && value_ce == scope) {
1031
12
    return true;
1032
228k
  } else if (ZEND_TYPE_HAS_NAME(member_type)) {
1033
228k
    const zend_class_entry *ce = zend_ce_from_type(scope, &member_type);
1034
228k
    return ce && instanceof_function(value_ce, ce);
1035
228k
  }
1036
1037
6
  return false;
1038
228k
}
1039
1040
static zend_always_inline bool i_zend_check_property_type(const zend_property_info *info, zval *property, bool strict)
1041
265k
{
1042
265k
  ZEND_ASSERT(!Z_ISREF_P(property));
1043
265k
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) {
1044
48.4k
    return 1;
1045
48.4k
  }
1046
1047
216k
  if (ZEND_TYPE_IS_COMPLEX(info->type) && Z_TYPE_P(property) == IS_OBJECT
1048
215k
      && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(property))) {
1049
215k
    return 1;
1050
215k
  }
1051
1052
1.24k
  uint32_t type_mask = ZEND_TYPE_FULL_MASK(info->type);
1053
1.24k
  ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC|MAY_BE_NEVER|MAY_BE_VOID)));
1054
1.24k
  return zend_verify_scalar_type_hint(type_mask, property, strict, false);
1055
1.24k
}
1056
1057
static zend_always_inline bool i_zend_verify_property_type(const zend_property_info *info, zval *property, bool strict)
1058
170k
{
1059
170k
  if (i_zend_check_property_type(info, property, strict)) {
1060
170k
    return 1;
1061
170k
  }
1062
1063
518
  zend_verify_property_type_error(info, property);
1064
518
  return 0;
1065
170k
}
1066
1067
169k
ZEND_API bool zend_never_inline zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) {
1068
169k
  return i_zend_verify_property_type(info, property, strict);
1069
169k
}
1070
1071
static zend_never_inline zval* zend_assign_to_typed_prop(const zend_property_info *info, zval *property_val, zval *value, zend_refcounted **garbage_ptr EXECUTE_DATA_DC)
1072
1.68k
{
1073
1.68k
  zval tmp;
1074
1075
1.68k
  if (UNEXPECTED(info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))) {
1076
124
    if ((info->flags & ZEND_ACC_READONLY) && !(Z_PROP_FLAG_P(property_val) & IS_PROP_REINITABLE)) {
1077
25
      zend_readonly_property_modification_error(info);
1078
25
      return &EG(uninitialized_zval);
1079
25
    }
1080
99
    if (info->flags & ZEND_ACC_PPP_SET_MASK && !zend_asymmetric_property_has_set_access(info)) {
1081
14
      zend_asymmetric_visibility_property_modification_error(info, "modify");
1082
14
      return &EG(uninitialized_zval);
1083
14
    }
1084
99
  }
1085
1086
1.65k
  ZVAL_DEREF(value);
1087
1.65k
  ZVAL_COPY(&tmp, value);
1088
1089
1.65k
  if (UNEXPECTED(!i_zend_verify_property_type(info, &tmp, EX_USES_STRICT_TYPES()))) {
1090
70
    zval_ptr_dtor(&tmp);
1091
70
    return &EG(uninitialized_zval);
1092
70
  }
1093
1094
1.58k
  Z_PROP_FLAG_P(property_val) &= ~IS_PROP_REINITABLE;
1095
1096
1.58k
  return zend_assign_to_variable_ex(property_val, &tmp, IS_TMP_VAR, EX_USES_STRICT_TYPES(), garbage_ptr);
1097
1.65k
}
1098
1099
203
static zend_always_inline bool zend_value_instanceof_static(const zval *zv) {
1100
203
  if (Z_TYPE_P(zv) != IS_OBJECT) {
1101
0
    return 0;
1102
0
  }
1103
1104
203
  zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
1105
203
  if (!called_scope) {
1106
5
    return 0;
1107
5
  }
1108
198
  return instanceof_function(Z_OBJCE_P(zv), called_scope);
1109
203
}
1110
1111
static zend_always_inline zend_class_entry *zend_fetch_ce_from_type(
1112
    const zend_type *type)
1113
39.1k
{
1114
39.1k
  zend_string *name = ZEND_TYPE_NAME(*type);
1115
39.1k
  zend_class_entry *ce;
1116
39.1k
  if (ZSTR_HAS_CE_CACHE(name)) {
1117
39.0k
    ce = ZSTR_GET_CE_CACHE(name);
1118
39.0k
    if (!ce) {
1119
3.27k
      ce = zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
1120
3.27k
      if (UNEXPECTED(!ce)) {
1121
        /* Cannot resolve */
1122
78
        return NULL;
1123
78
      }
1124
3.27k
    }
1125
39.0k
  } else {
1126
154
    ce = zend_fetch_class(name,
1127
154
      ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_SILENT);
1128
154
    if (UNEXPECTED(!ce)) {
1129
4
      return NULL;
1130
4
    }
1131
154
  }
1132
39.1k
  return ce;
1133
39.1k
}
1134
1135
static bool zend_check_intersection_type_from_list(
1136
  const zend_type_list *intersection_type_list,
1137
  zend_class_entry *arg_ce)
1138
512
{
1139
512
  zend_class_entry *ce;
1140
512
  const zend_type *list_type;
1141
1.37k
  ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
1142
1.37k
    ce = zend_fetch_ce_from_type(list_type);
1143
    /* If type is not an instance of one of the types taking part in the
1144
     * intersection it cannot be a valid instance of the whole intersection type. */
1145
1.37k
    if (!ce || !instanceof_function(arg_ce, ce)) {
1146
218
      return false;
1147
218
    }
1148
1.37k
  } ZEND_TYPE_LIST_FOREACH_END();
1149
294
  return true;
1150
512
}
1151
1152
static zend_always_inline bool zend_check_type_slow(
1153
    const zend_type *type, zval *arg, const zend_reference *ref,
1154
    bool is_return_type, bool is_internal)
1155
59.2k
{
1156
59.2k
  if (ZEND_TYPE_IS_COMPLEX(*type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
1157
38.6k
    zend_class_entry *ce;
1158
38.6k
    if (UNEXPECTED(ZEND_TYPE_HAS_LIST(*type))) {
1159
519
      if (ZEND_TYPE_IS_INTERSECTION(*type)) {
1160
76
        return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), Z_OBJCE_P(arg));
1161
443
      } else {
1162
443
        const zend_type *list_type;
1163
1.11k
        ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) {
1164
1.11k
          if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
1165
436
            if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), Z_OBJCE_P(arg))) {
1166
235
              return true;
1167
235
            }
1168
436
          } else {
1169
239
            ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
1170
239
            ce = zend_fetch_ce_from_type(list_type);
1171
            /* Instance of a single type part of a union is sufficient to pass the type check */
1172
239
            if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) {
1173
90
              return true;
1174
90
            }
1175
239
          }
1176
1.11k
        } ZEND_TYPE_LIST_FOREACH_END();
1177
443
      }
1178
38.0k
    } else {
1179
38.0k
      ce = zend_fetch_ce_from_type(type);
1180
      /* If we have a CE we check if it satisfies the type constraint,
1181
       * otherwise it will check if a standard type satisfies it. */
1182
38.0k
      if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) {
1183
37.9k
        return true;
1184
37.9k
      }
1185
38.0k
    }
1186
38.6k
  }
1187
1188
20.8k
  const uint32_t type_mask = ZEND_TYPE_FULL_MASK(*type);
1189
20.8k
  if ((type_mask & MAY_BE_CALLABLE) &&
1190
7.79k
    zend_is_callable(arg, is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0, NULL)) {
1191
7.55k
    return 1;
1192
7.55k
  }
1193
13.2k
  if ((type_mask & MAY_BE_STATIC) && zend_value_instanceof_static(arg)) {
1194
182
    return 1;
1195
182
  }
1196
13.1k
  if (ref && ZEND_REF_HAS_TYPE_SOURCES(ref)) {
1197
    /* We cannot have conversions for typed refs. */
1198
0
    return 0;
1199
0
  }
1200
13.1k
  if (is_internal && is_return_type) {
1201
    /* For internal returns, the type has to match exactly, because we're not
1202
     * going to check it for non-debug builds, and there will be no chance to
1203
     * apply coercions. */
1204
0
    return 0;
1205
0
  }
1206
1207
13.1k
  return zend_verify_scalar_type_hint(type_mask, arg,
1208
13.1k
    is_return_type ? ZEND_RET_USES_STRICT_TYPES() : ZEND_ARG_USES_STRICT_TYPES(),
1209
13.1k
    is_internal);
1210
1211
  /* Special handling for IS_VOID is not necessary (for return types),
1212
   * because this case is already checked at compile-time. */
1213
13.1k
}
1214
1215
static zend_always_inline bool zend_check_type(
1216
    const zend_type *type, zval *arg, bool is_return_type, bool is_internal)
1217
2.21M
{
1218
2.21M
  const zend_reference *ref = NULL;
1219
2.21M
  ZEND_ASSERT(ZEND_TYPE_IS_SET(*type));
1220
1221
2.21M
  if (UNEXPECTED(Z_ISREF_P(arg))) {
1222
5.31k
    ref = Z_REF_P(arg);
1223
5.31k
    arg = Z_REFVAL_P(arg);
1224
5.31k
  }
1225
1226
2.21M
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(*type, Z_TYPE_P(arg)))) {
1227
2.16M
    return 1;
1228
2.16M
  }
1229
1230
58.4k
  return zend_check_type_slow(type, arg, ref, is_return_type, is_internal);
1231
2.21M
}
1232
1233
ZEND_API bool zend_check_user_type_slow(
1234
    const zend_type *type, zval *arg, const zend_reference *ref, bool is_return_type)
1235
0
{
1236
0
  return zend_check_type_slow(
1237
0
    type, arg, ref, is_return_type, /* is_internal */ false);
1238
0
}
1239
1240
static zend_always_inline bool zend_verify_recv_arg_type(const zend_function *zf, uint32_t arg_num, zval *arg)
1241
5.79k
{
1242
5.79k
  const zend_arg_info *cur_arg_info;
1243
1244
5.79k
  ZEND_ASSERT(arg_num <= zf->common.num_args);
1245
5.79k
  cur_arg_info = &zf->common.arg_info[arg_num-1];
1246
1247
5.79k
  if (ZEND_TYPE_IS_SET(cur_arg_info->type)
1248
5.75k
      && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, false, false))) {
1249
627
    zend_verify_arg_error(zf, cur_arg_info, arg_num, arg);
1250
627
    return 0;
1251
627
  }
1252
1253
5.16k
  return 1;
1254
5.79k
}
1255
1256
static zend_always_inline bool zend_verify_variadic_arg_type(
1257
    const zend_function *zf, const zend_arg_info *arg_info, uint32_t arg_num, zval *arg)
1258
163
{
1259
163
  ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type));
1260
163
  if (UNEXPECTED(!zend_check_type(&arg_info->type, arg, false, false))) {
1261
30
    zend_verify_arg_error(zf, arg_info, arg_num, arg);
1262
30
    return 0;
1263
30
  }
1264
1265
133
  return 1;
1266
163
}
1267
1268
static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_types(const zend_function *fbc, zend_execute_data *call)
1269
1.41M
{
1270
1.41M
  uint32_t i;
1271
1.41M
  uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
1272
1.41M
  zval *arg = ZEND_CALL_ARG(call, 1);
1273
1274
3.24M
  for (i = 0; i < num_args; ++i) {
1275
1.83M
    zend_arg_info *cur_arg_info;
1276
1.83M
    if (EXPECTED(i < fbc->common.num_args)) {
1277
1.82M
      cur_arg_info = &fbc->common.arg_info[i];
1278
1.82M
    } else if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) {
1279
7.94k
      cur_arg_info = &fbc->common.arg_info[fbc->common.num_args];
1280
7.94k
    } else {
1281
0
      break;
1282
0
    }
1283
1284
1.83M
    if (ZEND_TYPE_IS_SET(cur_arg_info->type)
1285
1.82M
        && UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, false, /* is_internal */ true))) {
1286
499
      return 0;
1287
499
    }
1288
1.82M
    arg++;
1289
1.82M
  }
1290
1.41M
  return 1;
1291
1.41M
}
1292
1293
#if ZEND_DEBUG
1294
/* Determine whether an internal call should throw, because the passed arguments violate
1295
 * an arginfo constraint. This is only checked in debug builds. In release builds, we
1296
 * trust that arginfo matches what is enforced by zend_parse_parameters. */
1297
ZEND_API bool zend_internal_call_should_throw(const zend_function *fbc, zend_execute_data *call)
1298
1.59M
{
1299
1.59M
  if (fbc->internal_function.handler == ZEND_FN(pass) || (fbc->internal_function.fn_flags & ZEND_ACC_FAKE_CLOSURE)) {
1300
    /* Be lenient about the special pass function and about fake closures. */
1301
751
    return 0;
1302
751
  }
1303
1304
1.59M
  if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) {
1305
    /* Required argument not passed. */
1306
309
    return 1;
1307
309
  }
1308
1309
1.59M
  if (fbc->common.num_args < ZEND_CALL_NUM_ARGS(call)
1310
5.19k
      && !(fbc->common.fn_flags & ZEND_ACC_VARIADIC)) {
1311
    /* Too many arguments passed. For internal functions (unlike userland functions),
1312
     * this should always throw. */
1313
86
    return 1;
1314
86
  }
1315
1316
1.59M
  if ((fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) &&
1317
1.41M
      !zend_verify_internal_arg_types(fbc, call)) {
1318
499
    zend_clear_exception();
1319
499
    return 1;
1320
499
  }
1321
1322
1.59M
  return 0;
1323
1.59M
}
1324
1325
ZEND_API ZEND_COLD void zend_internal_call_arginfo_violation(const zend_function *fbc)
1326
0
{
1327
0
  zend_error_noreturn(E_ERROR, "Arginfo / zpp mismatch during call of %s%s%s()",
1328
0
    fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
1329
0
    fbc->common.scope ? "::" : "",
1330
0
    ZSTR_VAL(fbc->common.function_name));
1331
0
}
1332
1333
#ifndef ZEND_VERIFY_FUNC_INFO
1334
# define ZEND_VERIFY_FUNC_INFO 0
1335
#endif
1336
1337
576k
static void zend_verify_internal_func_info(const zend_function *fn, const zval *retval) {
1338
#if ZEND_VERIFY_FUNC_INFO
1339
  zend_string *name = fn->common.function_name;
1340
  const uint32_t type_mask = zend_get_internal_func_info(fn, NULL, NULL);
1341
  if (!type_mask) {
1342
    return;
1343
  }
1344
1345
  /* Always check refcount of arrays, as immutable arrays are RCN. */
1346
  if (Z_REFCOUNTED_P(retval) || Z_TYPE_P(retval) == IS_ARRAY) {
1347
    if (!(type_mask & MAY_BE_RC1)) {
1348
      zend_error_noreturn(E_CORE_ERROR, "%s() missing rc1", ZSTR_VAL(name));
1349
    }
1350
    if (Z_REFCOUNT_P(retval) > 1 && !(type_mask & MAY_BE_RCN)) {
1351
      zend_error_noreturn(E_CORE_ERROR, "%s() missing rcn", ZSTR_VAL(name));
1352
    }
1353
  }
1354
1355
  const uint32_t type = 1u << Z_TYPE_P(retval);
1356
  if (!(type_mask & type)) {
1357
    zend_error_noreturn(E_CORE_ERROR, "%s() missing type %s",
1358
      ZSTR_VAL(name), zend_get_type_by_const(Z_TYPE_P(retval)));
1359
  }
1360
1361
  if (Z_TYPE_P(retval) == IS_ARRAY) {
1362
    const HashTable *ht = Z_ARRVAL_P(retval);
1363
    uint32_t num_checked = 0;
1364
    zend_string *str;
1365
    zval *val;
1366
    ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) {
1367
      if (str) {
1368
        if (!(type_mask & MAY_BE_ARRAY_KEY_STRING)) {
1369
          zend_error_noreturn(E_CORE_ERROR,
1370
            "%s() missing array_key_string", ZSTR_VAL(name));
1371
        }
1372
      } else {
1373
        if (!(type_mask & MAY_BE_ARRAY_KEY_LONG)) {
1374
          zend_error_noreturn(E_CORE_ERROR,
1375
            "%s() missing array_key_long", ZSTR_VAL(name));
1376
        }
1377
      }
1378
1379
      const uint32_t array_type = 1u << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT);
1380
      if (!(type_mask & array_type)) {
1381
        zend_error_noreturn(E_CORE_ERROR,
1382
          "%s() missing array element type %s",
1383
          ZSTR_VAL(name), zend_get_type_by_const(Z_TYPE_P(retval)));
1384
      }
1385
1386
      /* Don't check all elements of large arrays. */
1387
      if (++num_checked > 16) {
1388
        break;
1389
      }
1390
    } ZEND_HASH_FOREACH_END();
1391
  }
1392
#endif
1393
576k
}
1394
#endif
1395
1396
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(const zend_execute_data *execute_data)
1397
188
{
1398
188
  const zend_execute_data *ptr = EX(prev_execute_data);
1399
1400
188
  if (ptr && ptr->func && ZEND_USER_CODE(ptr->func->common.type)) {
1401
185
    zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed in %s on line %d and %s %d expected",
1402
185
      EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "",
1403
185
      EX(func)->common.scope ? "::" : "",
1404
185
      ZSTR_VAL(EX(func)->common.function_name),
1405
185
      EX_NUM_ARGS(),
1406
185
      ZSTR_VAL(ptr->func->op_array.filename),
1407
185
      ptr->opline->lineno,
1408
185
      EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least",
1409
185
      EX(func)->common.required_num_args);
1410
185
  } else {
1411
3
    zend_throw_error(zend_ce_argument_count_error, "Too few arguments to function %s%s%s(), %d passed and %s %d expected",
1412
3
      EX(func)->common.scope ? ZSTR_VAL(EX(func)->common.scope->name) : "",
1413
3
      EX(func)->common.scope ? "::" : "",
1414
3
      ZSTR_VAL(EX(func)->common.function_name),
1415
3
      EX_NUM_ARGS(),
1416
3
      EX(func)->common.required_num_args == EX(func)->common.num_args ? "exactly" : "at least",
1417
3
      EX(func)->common.required_num_args);
1418
3
  }
1419
188
}
1420
1421
ZEND_API ZEND_COLD void zend_verify_return_error(const zend_function *zf, const zval *value)
1422
335
{
1423
335
  const zend_arg_info *arg_info = &zf->common.arg_info[-1];
1424
335
  const char *fname, *fsep, *fclass;
1425
335
  zend_string *need_msg;
1426
335
  const char *given_msg;
1427
1428
335
  zend_verify_type_error_common(
1429
335
    zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);
1430
1431
335
  zend_type_error("%s%s%s(): Return value must be of type %s, %s returned",
1432
335
    fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg);
1433
1434
335
  zend_string_release(need_msg);
1435
335
}
1436
1437
ZEND_API ZEND_COLD void zend_verify_never_error(const zend_function *zf)
1438
13
{
1439
13
  zend_string *func_name = get_function_or_method_name(zf);
1440
1441
13
  zend_type_error("%s(): never-returning %s must not implicitly return",
1442
13
    ZSTR_VAL(func_name), zf->common.scope ? "method" : "function");
1443
1444
13
  zend_string_release(func_name);
1445
13
}
1446
1447
#if ZEND_DEBUG
1448
static ZEND_COLD void zend_verify_internal_return_error(const zend_function *zf, const zval *value)
1449
0
{
1450
0
  const zend_arg_info *arg_info = &zf->common.arg_info[-1];
1451
0
  const char *fname, *fsep, *fclass;
1452
0
  zend_string *need_msg;
1453
0
  const char *given_msg;
1454
1455
0
  zend_verify_type_error_common(
1456
0
    zf, arg_info, value, &fname, &fsep, &fclass, &need_msg, &given_msg);
1457
1458
0
  zend_error_noreturn(E_CORE_ERROR, "%s%s%s(): Return value must be of type %s, %s returned",
1459
0
    fclass, fsep, fname, ZSTR_VAL(need_msg), given_msg);
1460
0
}
1461
1462
static ZEND_COLD void zend_verify_void_return_error(const zend_function *zf, const char *returned_msg, const char *returned_kind)
1463
0
{
1464
0
  const char *fname = ZSTR_VAL(zf->common.function_name);
1465
0
  const char *fsep;
1466
0
  const char *fclass;
1467
1468
0
  if (zf->common.scope) {
1469
0
    fsep =  "::";
1470
0
    fclass = ZSTR_VAL(zf->common.scope->name);
1471
0
  } else {
1472
0
    fsep =  "";
1473
0
    fclass = "";
1474
0
  }
1475
1476
0
  zend_type_error("%s%s%s() must not return a value, %s%s returned",
1477
0
    fclass, fsep, fname, returned_msg, returned_kind);
1478
0
}
1479
1480
ZEND_API bool zend_verify_internal_return_type(const zend_function *zf, zval *ret)
1481
1.12M
{
1482
1.12M
  const zend_arg_info *ret_info = zf->internal_function.arg_info - 1;
1483
1484
1.12M
  if (ZEND_TYPE_FULL_MASK(ret_info->type) & MAY_BE_VOID) {
1485
741k
    if (UNEXPECTED(Z_TYPE_P(ret) != IS_NULL)) {
1486
0
      zend_verify_void_return_error(zf, zend_zval_value_name(ret), "");
1487
0
      return 0;
1488
0
    }
1489
741k
    return 1;
1490
741k
  }
1491
1492
385k
  if (UNEXPECTED(!zend_check_type(&ret_info->type, ret, true, /* is_internal */ true))) {
1493
0
    zend_verify_internal_return_error(zf, ret);
1494
0
    return 0;
1495
0
  }
1496
1497
385k
  return 1;
1498
385k
}
1499
#endif
1500
1501
static ZEND_COLD void zend_verify_missing_return_type(const zend_function *zf)
1502
74
{
1503
  /* VERIFY_RETURN_TYPE is not emitted for "void" functions, so this is always an error. */
1504
74
  zend_verify_return_error(zf, NULL);
1505
74
}
1506
1507
static zend_always_inline bool zend_check_class_constant_type(const zend_class_constant *c, zval *constant)
1508
245
{
1509
245
  ZEND_ASSERT(!Z_ISREF_P(constant));
1510
245
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(c->type, Z_TYPE_P(constant)))) {
1511
16
    return 1;
1512
16
  }
1513
1514
229
  if (((ZEND_TYPE_PURE_MASK(c->type) & MAY_BE_STATIC) || ZEND_TYPE_IS_COMPLEX(c->type)) && Z_TYPE_P(constant) == IS_OBJECT
1515
204
    && zend_check_and_resolve_property_or_class_constant_class_type(c->ce, c->type, Z_OBJCE_P(constant))) {
1516
164
    return 1;
1517
164
  }
1518
1519
65
  uint32_t type_mask = ZEND_TYPE_FULL_MASK(c->type);
1520
65
  ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_NEVER|MAY_BE_VOID)));
1521
65
  return zend_verify_scalar_type_hint(type_mask, constant, true, false);
1522
65
}
1523
1524
ZEND_API bool zend_never_inline zend_verify_class_constant_type(const zend_class_constant *c, const zend_string *name, zval *constant)
1525
245
{
1526
245
  if (!zend_check_class_constant_type(c, constant)) {
1527
65
    zend_verify_class_constant_type_error(c, name, constant);
1528
65
    return 0;
1529
65
  }
1530
1531
180
  return 1;
1532
245
}
1533
1534
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(const zend_object *object)
1535
7
{
1536
7
  zend_throw_error(NULL, "Cannot use object of type %s as array", ZSTR_VAL(object->ce->name));
1537
7
}
1538
1539
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_access(const zval *offset)
1540
135
{
1541
135
  zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_RW);
1542
135
}
1543
1544
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_isset(const zval *offset)
1545
33
{
1546
33
  zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_IS);
1547
33
}
1548
1549
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_unset(const zval *offset)
1550
6
{
1551
6
  zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET);
1552
6
}
1553
1554
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset, int type)
1555
261
{
1556
261
  zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, type);
1557
261
}
1558
1559
static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)
1560
1.97k
{
1561
1.97k
  obj->handlers->write_dimension(obj, dim, value);
1562
1563
1.97k
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1564
64
    ZVAL_COPY(EX_VAR(opline->result.var), value);
1565
64
  }
1566
1.97k
}
1567
1568
static void frameless_observed_call_copy(zend_execute_data *call, uint32_t arg, zval *zv)
1569
0
{
1570
0
  if (Z_ISUNDEF_P(zv)) {
1571
0
    ZVAL_NULL(ZEND_CALL_VAR_NUM(call, arg));
1572
0
  } else {
1573
0
    ZVAL_COPY_DEREF(ZEND_CALL_VAR_NUM(call, arg), zv);
1574
0
  }
1575
0
}
1576
1577
ZEND_API void zend_frameless_observed_call(zend_execute_data *execute_data)
1578
0
{
1579
0
  const zend_op *opline = EX(opline);
1580
0
  uint8_t num_args = ZEND_FLF_NUM_ARGS(opline->opcode);
1581
0
  zend_function *fbc = ZEND_FLF_FUNC(opline);
1582
0
  zval *result = EX_VAR(opline->result.var);
1583
1584
0
  zend_execute_data *call = zend_vm_stack_push_call_frame_ex(zend_vm_calc_used_stack(num_args, fbc), ZEND_CALL_NESTED_FUNCTION, fbc, num_args, NULL);
1585
0
  call->prev_execute_data = execute_data;
1586
1587
0
  switch (num_args) {
1588
0
    case 3: frameless_observed_call_copy(call, 2, zend_get_zval_ptr(opline+1, (opline+1)->op1_type, &(opline+1)->op1, execute_data)); ZEND_FALLTHROUGH;
1589
0
    case 2: frameless_observed_call_copy(call, 1, zend_get_zval_ptr(opline, opline->op2_type, &opline->op2, execute_data)); ZEND_FALLTHROUGH;
1590
0
    case 1: frameless_observed_call_copy(call, 0, zend_get_zval_ptr(opline, opline->op1_type, &opline->op1, execute_data));
1591
0
  }
1592
1593
0
  EG(current_execute_data) = call;
1594
1595
0
  zend_observer_fcall_begin_prechecked(call, ZEND_OBSERVER_DATA(fbc));
1596
0
  fbc->internal_function.handler(call, result);
1597
0
  zend_observer_fcall_end(call, result);
1598
1599
0
  EG(current_execute_data) = execute_data;
1600
1601
0
  if (UNEXPECTED(EG(exception) != NULL)) {
1602
0
    zend_rethrow_exception(execute_data);
1603
0
  }
1604
1605
0
  zend_vm_stack_free_args(call);
1606
1607
0
  uint32_t call_info = ZEND_CALL_INFO(call);
1608
0
  if (UNEXPECTED(call_info & ZEND_CALL_ALLOCATED)) {
1609
0
    zend_vm_stack_free_call_frame_ex(call_info, call);
1610
0
  } else {
1611
0
    EG(vm_stack_top) = (zval*)call;
1612
0
  }
1613
0
}
1614
1615
1616
static zend_always_inline int zend_binary_op(zval *ret, zval *op1, zval *op2 OPLINE_DC)
1617
1.42M
{
1618
1.42M
  static const binary_op_type zend_binary_ops[] = {
1619
1.42M
    add_function,
1620
1.42M
    sub_function,
1621
1.42M
    mul_function,
1622
1.42M
    div_function,
1623
1.42M
    mod_function,
1624
1.42M
    shift_left_function,
1625
1.42M
    shift_right_function,
1626
1.42M
    concat_function,
1627
1.42M
    bitwise_or_function,
1628
1.42M
    bitwise_and_function,
1629
1.42M
    bitwise_xor_function,
1630
1.42M
    pow_function
1631
1.42M
  };
1632
  /* size_t cast makes GCC to better optimize 64-bit PIC code */
1633
1.42M
  size_t opcode = (size_t)opline->extended_value;
1634
1635
1.42M
  return zend_binary_ops[opcode - ZEND_ADD](ret, op1, op2);
1636
1.42M
}
1637
1638
static zend_never_inline void zend_binary_assign_op_obj_dim(zend_object *obj, zval *property OPLINE_DC EXECUTE_DATA_DC)
1639
60
{
1640
60
  zval *value;
1641
60
  zval *z;
1642
60
  zval rv, res;
1643
1644
60
  GC_ADDREF(obj);
1645
60
  if (property && UNEXPECTED(Z_ISUNDEF_P(property))) {
1646
0
    property = ZVAL_UNDEFINED_OP2();
1647
0
  }
1648
60
  value = get_op_data_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1);
1649
60
  if ((z = obj->handlers->read_dimension(obj, property, BP_VAR_R, &rv)) != NULL) {
1650
1651
53
    if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) {
1652
45
      obj->handlers->write_dimension(obj, property, &res);
1653
45
    }
1654
53
    if (z == &rv) {
1655
37
      zval_ptr_dtor(&rv);
1656
37
    }
1657
53
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1658
5
      ZVAL_COPY(EX_VAR(opline->result.var), &res);
1659
5
    }
1660
53
    zval_ptr_dtor(&res);
1661
53
  } else {
1662
7
    zend_use_object_as_array(obj);
1663
7
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1664
2
      ZVAL_NULL(EX_VAR(opline->result.var));
1665
2
    }
1666
7
  }
1667
60
  FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
1668
60
  if (UNEXPECTED(GC_DELREF(obj) == 0)) {
1669
0
    zend_objects_store_del(obj);
1670
0
  }
1671
60
}
1672
1673
static zend_never_inline void zend_binary_assign_op_typed_ref(zend_reference *ref, zval *value OPLINE_DC EXECUTE_DATA_DC)
1674
170
{
1675
170
  zval z_copy;
1676
1677
  /* Make sure that in-place concatenation is used if the LHS is a string. */
1678
170
  if (opline->extended_value == ZEND_CONCAT && Z_TYPE(ref->val) == IS_STRING) {
1679
51
    concat_function(&ref->val, &ref->val, value);
1680
51
    ZEND_ASSERT(Z_TYPE(ref->val) == IS_STRING && "Concat should return string");
1681
51
    return;
1682
51
  }
1683
1684
119
  zend_binary_op(&z_copy, &ref->val, value OPLINE_CC);
1685
119
  if (EXPECTED(zend_verify_ref_assignable_zval(ref, &z_copy, EX_USES_STRICT_TYPES()))) {
1686
90
    zval_ptr_dtor(&ref->val);
1687
90
    ZVAL_COPY_VALUE(&ref->val, &z_copy);
1688
90
  } else {
1689
29
    zval_ptr_dtor(&z_copy);
1690
29
  }
1691
119
}
1692
1693
static zend_never_inline void zend_binary_assign_op_typed_prop(const zend_property_info *prop_info, zval *zptr, zval *value OPLINE_DC EXECUTE_DATA_DC)
1694
244
{
1695
244
  zval z_copy;
1696
1697
  /* Make sure that in-place concatenation is used if the LHS is a string. */
1698
244
  if (opline->extended_value == ZEND_CONCAT && Z_TYPE_P(zptr) == IS_STRING) {
1699
104
    concat_function(zptr, zptr, value);
1700
104
    ZEND_ASSERT(Z_TYPE_P(zptr) == IS_STRING && "Concat should return string");
1701
104
    return;
1702
104
  }
1703
1704
140
  zend_binary_op(&z_copy, zptr, value OPLINE_CC);
1705
140
  if (EXPECTED(zend_verify_property_type(prop_info, &z_copy, EX_USES_STRICT_TYPES()))) {
1706
102
    zval_ptr_dtor(zptr);
1707
102
    ZVAL_COPY_VALUE(zptr, &z_copy);
1708
102
  } else {
1709
38
    zval_ptr_dtor(&z_copy);
1710
38
  }
1711
140
}
1712
1713
static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type EXECUTE_DATA_DC)
1714
335
{
1715
335
  zend_long offset;
1716
1717
335
try_again:
1718
335
  switch(Z_TYPE_P(dim)) {
1719
132
    case IS_LONG:
1720
132
      return Z_LVAL_P(dim);
1721
83
    case IS_STRING:
1722
83
    {
1723
83
      bool trailing_data = false;
1724
      /* For BC reasons we allow errors so that we can warn on leading numeric string */
1725
83
      if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
1726
83
          /* allow errors */ true, NULL, &trailing_data)) {
1727
9
        if (UNEXPECTED(trailing_data) && type != BP_VAR_UNSET) {
1728
9
          zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
1729
9
        }
1730
9
        return offset;
1731
9
      }
1732
74
      zend_illegal_string_offset(dim, type);
1733
74
      return 0;
1734
83
    }
1735
36
    case IS_DOUBLE:
1736
      /* Suppress potential double warning */
1737
36
      zend_error(E_WARNING, "String offset cast occurred");
1738
36
      return zend_dval_to_lval_silent(Z_DVAL_P(dim));
1739
2
    case IS_UNDEF:
1740
2
      ZVAL_UNDEFINED_OP2();
1741
2
      ZEND_FALLTHROUGH;
1742
76
    case IS_NULL:
1743
77
    case IS_FALSE:
1744
78
    case IS_TRUE:
1745
78
      zend_error(E_WARNING, "String offset cast occurred");
1746
78
      break;
1747
0
    case IS_REFERENCE:
1748
0
      dim = Z_REFVAL_P(dim);
1749
0
      goto try_again;
1750
6
    default:
1751
6
      zend_illegal_string_offset(dim, type);
1752
6
      return 0;
1753
335
  }
1754
1755
78
  return zval_get_long_func(dim, /* is_strict */ false);
1756
335
}
1757
1758
ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void)
1759
154
{
1760
154
  const char *msg = NULL;
1761
154
  const zend_execute_data *execute_data = EG(current_execute_data);
1762
154
  const zend_op *opline = execute_data->opline;
1763
1764
154
  if (UNEXPECTED(EG(exception) != NULL)) {
1765
7
    return;
1766
7
  }
1767
1768
147
  switch (opline->opcode) {
1769
8
    case ZEND_ASSIGN_DIM_OP:
1770
8
      msg = "Cannot use assign-op operators with string offsets";
1771
8
      break;
1772
6
    case ZEND_FETCH_LIST_W:
1773
6
      msg = "Cannot create references to/from string offsets";
1774
6
      break;
1775
70
    case ZEND_FETCH_DIM_W:
1776
110
    case ZEND_FETCH_DIM_RW:
1777
115
    case ZEND_FETCH_DIM_FUNC_ARG:
1778
133
    case ZEND_FETCH_DIM_UNSET:
1779
133
      switch (opline->extended_value) {
1780
43
        case ZEND_FETCH_DIM_REF:
1781
43
          msg = "Cannot create references to/from string offsets";
1782
43
          break;
1783
34
        case ZEND_FETCH_DIM_DIM:
1784
34
          msg = "Cannot use string offset as an array";
1785
34
          break;
1786
48
        case ZEND_FETCH_DIM_OBJ:
1787
48
          msg = "Cannot use string offset as an object";
1788
48
          break;
1789
8
        case ZEND_FETCH_DIM_INCDEC:
1790
8
          msg = "Cannot increment/decrement string offsets";
1791
8
          break;
1792
0
        EMPTY_SWITCH_DEFAULT_CASE();
1793
133
      }
1794
133
      break;
1795
133
    EMPTY_SWITCH_DEFAULT_CASE();
1796
147
  }
1797
147
  ZEND_ASSERT(msg != NULL);
1798
147
  zend_throw_error(NULL, "%s", msg);
1799
147
}
1800
1801
ZEND_COLD static zend_result ZEND_FASTCALL get_deprecation_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix)
1802
589
{
1803
589
  *message_suffix = ZSTR_EMPTY_ALLOC();
1804
1805
589
  if (!attributes) {
1806
0
    return SUCCESS;
1807
0
  }
1808
1809
589
  zend_attribute *deprecated = zend_get_attribute_str(attributes, "deprecated", sizeof("deprecated")-1);
1810
1811
589
  if (!deprecated) {
1812
0
    return SUCCESS;
1813
0
  }
1814
1815
589
  if (deprecated->argc == 0) {
1816
195
    return SUCCESS;
1817
195
  }
1818
1819
394
  zend_result result = FAILURE;
1820
1821
394
  zend_string *message = ZSTR_EMPTY_ALLOC();
1822
394
  zend_string *since = ZSTR_EMPTY_ALLOC();
1823
1824
394
  zval obj;
1825
394
  ZVAL_UNDEF(&obj);
1826
394
  zval *z;
1827
1828
  /* Construct the Deprecated object to correctly handle parameter processing. */
1829
394
  if (FAILURE == zend_get_attribute_object(&obj, zend_ce_deprecated, deprecated, scope, NULL)) {
1830
23
    goto out;
1831
23
  }
1832
1833
  /* Extract the $message property. */
1834
371
  z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL);
1835
371
  ZEND_ASSERT(z != &EG(uninitialized_zval));
1836
371
  if (Z_TYPE_P(z) == IS_STRING) {
1837
306
    message = Z_STR_P(z);
1838
306
  }
1839
1840
  /* Extract the $since property. */
1841
371
  z = zend_read_property_ex(zend_ce_deprecated, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_SINCE), false, NULL);
1842
371
  ZEND_ASSERT(z != &EG(uninitialized_zval));
1843
371
  if (Z_TYPE_P(z) == IS_STRING) {
1844
216
    since = Z_STR_P(z);
1845
216
  }
1846
1847
  /* Construct the suffix. */
1848
371
  *message_suffix = zend_strpprintf_unchecked(
1849
371
    0,
1850
371
    "%s%S%s%S",
1851
371
    ZSTR_LEN(since) > 0 ? " since " : "",
1852
371
    since,
1853
371
    ZSTR_LEN(message) > 0 ? ", " : "",
1854
371
    message
1855
371
  );
1856
1857
371
  result = SUCCESS;
1858
1859
394
 out:
1860
1861
394
  zval_ptr_dtor(&obj);
1862
1863
394
  return result;
1864
371
}
1865
1866
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
1867
307
{
1868
307
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1869
1870
307
  if (get_deprecation_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) {
1871
15
    return;
1872
15
  }
1873
1874
292
  int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_DEPRECATED : E_USER_DEPRECATED;
1875
1876
292
  if (fbc->common.scope) {
1877
139
    zend_error_unchecked(code, "Method %s::%s() is deprecated%S",
1878
139
      ZSTR_VAL(fbc->common.scope->name),
1879
139
      ZSTR_VAL(fbc->common.function_name),
1880
139
      message_suffix
1881
139
    );
1882
153
  } else {
1883
153
    zend_error_unchecked(code, "Function %s() is deprecated%S",
1884
153
      ZSTR_VAL(fbc->common.function_name),
1885
153
      message_suffix
1886
153
    );
1887
153
  }
1888
1889
292
  zend_string_release(message_suffix);
1890
292
}
1891
1892
ZEND_COLD static zend_result ZEND_FASTCALL get_nodiscard_suffix_from_attribute(HashTable *attributes, zend_class_entry* scope, zend_string **message_suffix)
1893
250
{
1894
250
  *message_suffix = ZSTR_EMPTY_ALLOC();
1895
1896
250
  if (!attributes) {
1897
0
    return SUCCESS;
1898
0
  }
1899
1900
250
  zend_attribute *nodiscard = zend_get_attribute_str(attributes, "nodiscard", sizeof("nodiscard")-1);
1901
1902
250
  if (!nodiscard) {
1903
0
    return SUCCESS;
1904
0
  }
1905
1906
250
  if (nodiscard->argc == 0) {
1907
226
    return SUCCESS;
1908
226
  }
1909
1910
24
  zend_result result = FAILURE;
1911
1912
24
  zend_string *message = ZSTR_EMPTY_ALLOC();
1913
1914
24
  zval obj;
1915
24
  ZVAL_UNDEF(&obj);
1916
24
  zval *z;
1917
1918
  /* Construct the NoDiscard object to correctly handle parameter processing. */
1919
24
  if (FAILURE == zend_get_attribute_object(&obj, zend_ce_nodiscard, nodiscard, scope, NULL)) {
1920
4
    goto out;
1921
4
  }
1922
1923
  /* Extract the $message property. */
1924
20
  z = zend_read_property_ex(zend_ce_nodiscard, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL);
1925
20
  ZEND_ASSERT(z != &EG(uninitialized_zval));
1926
20
  if (Z_TYPE_P(z) == IS_STRING) {
1927
20
    message = Z_STR_P(z);
1928
20
  }
1929
1930
  /* Construct the suffix. */
1931
20
  *message_suffix = zend_strpprintf_unchecked(
1932
20
    0,
1933
20
    "%s%S",
1934
20
    ZSTR_LEN(message) > 0 ? ", " : "",
1935
20
    message
1936
20
  );
1937
1938
20
  result = SUCCESS;
1939
1940
24
 out:
1941
1942
24
  zval_ptr_dtor(&obj);
1943
1944
24
  return result;
1945
20
}
1946
1947
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_nodiscard_function(const zend_function *fbc)
1948
250
{
1949
250
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1950
1951
250
  if (get_nodiscard_suffix_from_attribute(fbc->common.attributes, fbc->common.scope, &message_suffix) == FAILURE) {
1952
4
    return;
1953
4
  }
1954
1955
246
  int code = fbc->type == ZEND_INTERNAL_FUNCTION ? E_WARNING : E_USER_WARNING;
1956
1957
246
  if (fbc->common.scope) {
1958
52
    zend_error_unchecked(code, "The return value of method %s::%s() should either be used or intentionally ignored by casting it as (void)%S",
1959
52
      ZSTR_VAL(fbc->common.scope->name),
1960
52
      ZSTR_VAL(fbc->common.function_name),
1961
52
      message_suffix
1962
52
    );
1963
194
  } else {
1964
194
    zend_error_unchecked(code, "The return value of function %s() should either be used or intentionally ignored by casting it as (void)%S",
1965
194
      ZSTR_VAL(fbc->common.function_name),
1966
194
      message_suffix
1967
194
    );
1968
194
  }
1969
1970
246
  zend_string_release(message_suffix);
1971
246
}
1972
1973
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_class_constant(const zend_class_constant *c, const zend_string *constant_name)
1974
92
{
1975
92
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1976
1977
92
  if (get_deprecation_suffix_from_attribute(c->attributes, c->ce, &message_suffix) == FAILURE) {
1978
5
    return;
1979
5
  }
1980
1981
87
  int code = c->ce->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED;
1982
87
  char *type = (ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE) ? "Enum case" : "Constant";
1983
1984
87
  zend_error_unchecked(code, "%s %s::%s is deprecated%S",
1985
87
    type,
1986
87
    ZSTR_VAL(c->ce->name),
1987
87
    ZSTR_VAL(constant_name),
1988
87
    message_suffix
1989
87
  );
1990
1991
87
  zend_string_release(message_suffix);
1992
87
}
1993
1994
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_constant(const zend_constant *c, const zend_string *constant_name)
1995
124
{
1996
124
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
1997
1998
124
  if (get_deprecation_suffix_from_attribute(c->attributes, NULL, &message_suffix) == FAILURE) {
1999
0
    return;
2000
0
  }
2001
2002
124
  int code = ZEND_CONSTANT_MODULE_NUMBER(c) == PHP_USER_CONSTANT ? E_USER_DEPRECATED : E_DEPRECATED;
2003
2004
124
  zend_error_unchecked(code, "Constant %s is deprecated%S",
2005
124
    ZSTR_VAL(constant_name),
2006
124
    message_suffix
2007
124
  );
2008
2009
124
  zend_string_release(message_suffix);
2010
124
}
2011
2012
ZEND_API ZEND_COLD void zend_use_of_deprecated_trait(
2013
  zend_class_entry *trait,
2014
  const zend_string *used_by
2015
66
) {
2016
66
  zend_string *message_suffix = ZSTR_EMPTY_ALLOC();
2017
2018
66
  if (get_deprecation_suffix_from_attribute(trait->attributes, trait, &message_suffix) == FAILURE) {
2019
3
    return;
2020
3
  }
2021
2022
63
  int code = trait->type == ZEND_INTERNAL_CLASS ? E_DEPRECATED : E_USER_DEPRECATED;
2023
2024
63
  zend_error_unchecked(code, "Trait %s used by %s is deprecated%S",
2025
63
    ZSTR_VAL(trait->name),
2026
63
    ZSTR_VAL(used_by),
2027
63
    message_suffix
2028
63
  );
2029
2030
63
  zend_string_release(message_suffix);
2031
63
}
2032
2033
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void)
2034
1.10k
{
2035
1.10k
  zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
2036
1.10k
}
2037
2038
static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC)
2039
433
{
2040
433
  zend_uchar c;
2041
433
  size_t string_len;
2042
433
  zend_long offset;
2043
433
  zend_string *s;
2044
2045
  /* separate string */
2046
433
  if (Z_REFCOUNTED_P(str) && Z_REFCOUNT_P(str) == 1) {
2047
193
    s = Z_STR_P(str);
2048
240
  } else {
2049
240
    s = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
2050
240
    ZSTR_H(s) = ZSTR_H(Z_STR_P(str));
2051
240
    if (Z_REFCOUNTED_P(str)) {
2052
50
      GC_DELREF(Z_STR_P(str));
2053
50
    }
2054
240
    ZVAL_NEW_STR(str, s);
2055
240
  }
2056
2057
433
  if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
2058
252
    offset = Z_LVAL_P(dim);
2059
252
  } else {
2060
    /* The string may be destroyed while throwing the notice.
2061
     * Temporarily increase the refcount to detect this situation. */
2062
181
    GC_ADDREF(s);
2063
181
    offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC);
2064
181
    if (UNEXPECTED(GC_DELREF(s) == 0)) {
2065
0
      zend_string_efree(s);
2066
0
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2067
0
        ZVAL_NULL(EX_VAR(opline->result.var));
2068
0
      }
2069
0
      return;
2070
0
    }
2071
    /* Illegal offset assignment */
2072
181
    if (UNEXPECTED(EG(exception) != NULL)) {
2073
73
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2074
11
        ZVAL_UNDEF(EX_VAR(opline->result.var));
2075
11
      }
2076
73
      return;
2077
73
    }
2078
181
  }
2079
2080
360
  if (UNEXPECTED(offset < -(zend_long)ZSTR_LEN(s))) {
2081
    /* Error on negative offset */
2082
62
    zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);
2083
62
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2084
56
      ZVAL_NULL(EX_VAR(opline->result.var));
2085
56
    }
2086
62
    return;
2087
62
  }
2088
2089
298
  if (offset < 0) { /* Handle negative offset */
2090
48
    offset += (zend_long)ZSTR_LEN(s);
2091
48
  }
2092
2093
298
  if (UNEXPECTED(Z_TYPE_P(value) != IS_STRING)) {
2094
88
    zend_string *tmp;
2095
2096
    /* The string may be destroyed while throwing the notice.
2097
     * Temporarily increase the refcount to detect this situation. */
2098
88
    GC_ADDREF(s);
2099
88
    if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) {
2100
0
      zval_undefined_cv((opline+1)->op1.var EXECUTE_DATA_CC);
2101
0
    }
2102
    /* Convert to string, just the time to pick the 1st byte */
2103
88
    tmp = zval_try_get_string_func(value);
2104
88
    if (UNEXPECTED(GC_DELREF(s) == 0)) {
2105
0
      zend_string_efree(s);
2106
0
      if (tmp) {
2107
0
        zend_string_release_ex(tmp, 0);
2108
0
      }
2109
0
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2110
0
        ZVAL_NULL(EX_VAR(opline->result.var));
2111
0
      }
2112
0
      return;
2113
0
    }
2114
88
    if (UNEXPECTED(!tmp)) {
2115
11
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2116
0
        ZVAL_UNDEF(EX_VAR(opline->result.var));
2117
0
      }
2118
11
      return;
2119
11
    }
2120
2121
77
    string_len = ZSTR_LEN(tmp);
2122
77
    c = (zend_uchar)ZSTR_VAL(tmp)[0];
2123
77
    zend_string_release_ex(tmp, 0);
2124
210
  } else {
2125
210
    string_len = Z_STRLEN_P(value);
2126
210
    c = (zend_uchar)Z_STRVAL_P(value)[0];
2127
210
  }
2128
2129
287
  if (UNEXPECTED(string_len != 1)) {
2130
72
    if (string_len == 0) {
2131
      /* Error on empty input string */
2132
27
      zend_throw_error(NULL, "Cannot assign an empty string to a string offset");
2133
27
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2134
25
        ZVAL_NULL(EX_VAR(opline->result.var));
2135
25
      }
2136
27
      return;
2137
27
    }
2138
2139
    /* The string may be destroyed while throwing the notice.
2140
     * Temporarily increase the refcount to detect this situation. */
2141
45
    GC_ADDREF(s);
2142
45
    zend_error(E_WARNING, "Only the first byte will be assigned to the string offset");
2143
45
    if (UNEXPECTED(GC_DELREF(s) == 0)) {
2144
0
      zend_string_efree(s);
2145
0
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2146
0
        ZVAL_NULL(EX_VAR(opline->result.var));
2147
0
      }
2148
0
      return;
2149
0
    }
2150
    /* Illegal offset assignment */
2151
45
    if (UNEXPECTED(EG(exception) != NULL)) {
2152
0
      if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2153
0
        ZVAL_UNDEF(EX_VAR(opline->result.var));
2154
0
      }
2155
0
      return;
2156
0
    }
2157
45
  }
2158
2159
260
  if ((size_t)offset >= ZSTR_LEN(s)) {
2160
    /* Extend string if needed */
2161
48
    zend_long old_len = ZSTR_LEN(s);
2162
48
    ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0));
2163
48
    memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
2164
48
    Z_STRVAL_P(str)[offset+1] = 0;
2165
212
  } else {
2166
212
    zend_string_forget_hash_val(Z_STR_P(str));
2167
212
  }
2168
2169
260
  Z_STRVAL_P(str)[offset] = c;
2170
2171
260
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2172
    /* Return the new character */
2173
68
    ZVAL_CHAR(EX_VAR(opline->result.var), c);
2174
68
  }
2175
260
}
2176
2177
static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *ref)
2178
228
{
2179
228
  zend_property_info *prop;
2180
684
  ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
2181
684
    if (!(ZEND_TYPE_FULL_MASK(prop->type) & MAY_BE_DOUBLE)) {
2182
173
      return prop;
2183
173
    }
2184
684
  } ZEND_REF_FOREACH_TYPE_SOURCES_END();
2185
55
  return NULL;
2186
228
}
2187
2188
static ZEND_COLD zend_long zend_throw_incdec_ref_error(zend_property_info *error_prop OPLINE_DC)
2189
173
{
2190
173
  zend_string *type_str = zend_type_to_string(error_prop->type);
2191
173
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2192
92
    zend_type_error(
2193
92
      "Cannot increment a reference held by property %s::$%s of type %s past its maximal value",
2194
92
      ZSTR_VAL(error_prop->ce->name),
2195
92
      zend_get_unmangled_property_name(error_prop->name),
2196
92
      ZSTR_VAL(type_str));
2197
92
    zend_string_release(type_str);
2198
92
    return ZEND_LONG_MAX;
2199
92
  } else {
2200
81
    zend_type_error(
2201
81
      "Cannot decrement a reference held by property %s::$%s of type %s past its minimal value",
2202
81
      ZSTR_VAL(error_prop->ce->name),
2203
81
      zend_get_unmangled_property_name(error_prop->name),
2204
81
      ZSTR_VAL(type_str));
2205
81
    zend_string_release(type_str);
2206
81
    return ZEND_LONG_MIN;
2207
81
  }
2208
173
}
2209
2210
103
static ZEND_COLD zend_long zend_throw_incdec_prop_error(zend_property_info *prop OPLINE_DC) {
2211
103
  zend_string *type_str = zend_type_to_string(prop->type);
2212
103
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2213
65
    zend_type_error("Cannot increment property %s::$%s of type %s past its maximal value",
2214
65
      ZSTR_VAL(prop->ce->name),
2215
65
      zend_get_unmangled_property_name(prop->name),
2216
65
      ZSTR_VAL(type_str));
2217
65
    zend_string_release(type_str);
2218
65
    return ZEND_LONG_MAX;
2219
65
  } else {
2220
38
    zend_type_error("Cannot decrement property %s::$%s of type %s past its minimal value",
2221
38
      ZSTR_VAL(prop->ce->name),
2222
38
      zend_get_unmangled_property_name(prop->name),
2223
38
      ZSTR_VAL(type_str));
2224
38
    zend_string_release(type_str);
2225
38
    return ZEND_LONG_MIN;
2226
38
  }
2227
103
}
2228
2229
static void zend_incdec_typed_ref(zend_reference *ref, zval *copy OPLINE_DC EXECUTE_DATA_DC)
2230
371
{
2231
371
  zval tmp;
2232
371
  zval *var_ptr = &ref->val;
2233
2234
371
  if (!copy) {
2235
274
    copy = &tmp;
2236
274
  }
2237
2238
371
  ZVAL_COPY(copy, var_ptr);
2239
2240
371
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2241
177
    increment_function(var_ptr);
2242
194
  } else {
2243
194
    decrement_function(var_ptr);
2244
194
  }
2245
2246
371
  if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) {
2247
228
    zend_property_info *error_prop = zend_get_prop_not_accepting_double(ref);
2248
228
    if (UNEXPECTED(error_prop)) {
2249
173
      zend_long val = zend_throw_incdec_ref_error(error_prop OPLINE_CC);
2250
173
      ZVAL_LONG(var_ptr, val);
2251
173
    }
2252
228
  } else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, EX_USES_STRICT_TYPES()))) {
2253
6
    zval_ptr_dtor(var_ptr);
2254
6
    ZVAL_COPY_VALUE(var_ptr, copy);
2255
6
    ZVAL_UNDEF(copy);
2256
137
  } else if (copy == &tmp) {
2257
101
    zval_ptr_dtor(&tmp);
2258
101
  }
2259
371
}
2260
2261
static void zend_incdec_typed_prop(zend_property_info *prop_info, zval *var_ptr, zval *copy OPLINE_DC EXECUTE_DATA_DC)
2262
69
{
2263
69
  zval tmp;
2264
2265
69
  if (!copy) {
2266
53
    copy = &tmp;
2267
53
  }
2268
2269
69
  ZVAL_COPY(copy, var_ptr);
2270
2271
69
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2272
46
    increment_function(var_ptr);
2273
46
  } else {
2274
23
    decrement_function(var_ptr);
2275
23
  }
2276
2277
69
  if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) {
2278
0
    if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2279
0
      zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
2280
0
      ZVAL_LONG(var_ptr, val);
2281
0
    }
2282
69
  } else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
2283
11
    zval_ptr_dtor(var_ptr);
2284
11
    ZVAL_COPY_VALUE(var_ptr, copy);
2285
11
    ZVAL_UNDEF(copy);
2286
58
  } else if (copy == &tmp) {
2287
47
    zval_ptr_dtor(&tmp);
2288
47
  }
2289
69
}
2290
2291
static void zend_pre_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC)
2292
1.44k
{
2293
1.44k
  if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
2294
772
    if (ZEND_IS_INCREMENT(opline->opcode)) {
2295
685
      fast_long_increment_function(prop);
2296
685
    } else {
2297
87
      fast_long_decrement_function(prop);
2298
87
    }
2299
772
    if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info
2300
117
        && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2301
82
      zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
2302
82
      ZVAL_LONG(prop, val);
2303
82
    }
2304
772
  } else {
2305
671
    do {
2306
671
      if (Z_ISREF_P(prop)) {
2307
142
        zend_reference *ref = Z_REF_P(prop);
2308
142
        prop = Z_REFVAL_P(prop);
2309
142
        if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
2310
106
          zend_incdec_typed_ref(ref, NULL OPLINE_CC EXECUTE_DATA_CC);
2311
106
          break;
2312
106
        }
2313
142
      }
2314
2315
565
      if (prop_info) {
2316
53
        zend_incdec_typed_prop(prop_info, prop, NULL OPLINE_CC EXECUTE_DATA_CC);
2317
512
      } else if (ZEND_IS_INCREMENT(opline->opcode)) {
2318
467
        increment_function(prop);
2319
467
      } else {
2320
45
        decrement_function(prop);
2321
45
      }
2322
565
    } while (0);
2323
671
  }
2324
1.44k
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2325
883
    ZVAL_COPY(EX_VAR(opline->result.var), prop);
2326
883
  }
2327
1.44k
}
2328
2329
static void zend_post_incdec_property_zval(zval *prop, zend_property_info *prop_info OPLINE_DC EXECUTE_DATA_DC)
2330
1.40k
{
2331
1.40k
  if (EXPECTED(Z_TYPE_P(prop) == IS_LONG)) {
2332
1.29k
    ZVAL_LONG(EX_VAR(opline->result.var), Z_LVAL_P(prop));
2333
1.29k
    if (ZEND_IS_INCREMENT(opline->opcode)) {
2334
258
      fast_long_increment_function(prop);
2335
1.03k
    } else {
2336
1.03k
      fast_long_decrement_function(prop);
2337
1.03k
    }
2338
1.29k
    if (UNEXPECTED(Z_TYPE_P(prop) != IS_LONG) && prop_info
2339
56
        && !(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2340
21
      zend_long val = zend_throw_incdec_prop_error(prop_info OPLINE_CC);
2341
21
      ZVAL_LONG(prop, val);
2342
21
    }
2343
1.29k
  } else {
2344
119
    if (Z_ISREF_P(prop)) {
2345
69
      zend_reference *ref = Z_REF_P(prop);
2346
69
      prop = Z_REFVAL_P(prop);
2347
69
      if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
2348
57
        zend_incdec_typed_ref(ref, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC);
2349
57
        return;
2350
57
      }
2351
69
    }
2352
2353
62
    if (prop_info) {
2354
16
      zend_incdec_typed_prop(prop_info, prop, EX_VAR(opline->result.var) OPLINE_CC EXECUTE_DATA_CC);
2355
46
    } else {
2356
46
      ZVAL_COPY(EX_VAR(opline->result.var), prop);
2357
46
      if (ZEND_IS_INCREMENT(opline->opcode)) {
2358
33
        increment_function(prop);
2359
33
      } else {
2360
13
        decrement_function(prop);
2361
13
      }
2362
46
    }
2363
62
  }
2364
1.40k
}
2365
2366
static zend_never_inline void zend_post_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC)
2367
34
{
2368
34
  zval rv;
2369
34
  zval *z;
2370
34
  zval z_copy;
2371
2372
34
  GC_ADDREF(object);
2373
34
  z =object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
2374
34
  if (UNEXPECTED(EG(exception))) {
2375
1
    OBJ_RELEASE(object);
2376
1
    ZVAL_UNDEF(EX_VAR(opline->result.var));
2377
1
    return;
2378
1
  }
2379
2380
33
  ZVAL_COPY_DEREF(&z_copy, z);
2381
33
  ZVAL_COPY(EX_VAR(opline->result.var), &z_copy);
2382
33
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2383
28
    increment_function(&z_copy);
2384
28
  } else {
2385
5
    decrement_function(&z_copy);
2386
5
  }
2387
33
  object->handlers->write_property(object, name, &z_copy, cache_slot);
2388
33
  OBJ_RELEASE(object);
2389
33
  zval_ptr_dtor(&z_copy);
2390
33
  if (z == &rv) {
2391
19
    zval_ptr_dtor(z);
2392
19
  }
2393
33
}
2394
2395
static zend_never_inline void zend_pre_incdec_overloaded_property(zend_object *object, zend_string *name, void **cache_slot OPLINE_DC EXECUTE_DATA_DC)
2396
268
{
2397
268
  zval rv;
2398
268
  zval *z;
2399
268
  zval z_copy;
2400
2401
268
  GC_ADDREF(object);
2402
268
  z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
2403
268
  if (UNEXPECTED(EG(exception))) {
2404
6
    OBJ_RELEASE(object);
2405
6
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2406
0
      ZVAL_NULL(EX_VAR(opline->result.var));
2407
0
    }
2408
6
    return;
2409
6
  }
2410
2411
262
  ZVAL_COPY_DEREF(&z_copy, z);
2412
262
  if (ZEND_IS_INCREMENT(opline->opcode)) {
2413
204
    increment_function(&z_copy);
2414
204
  } else {
2415
58
    decrement_function(&z_copy);
2416
58
  }
2417
262
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2418
15
    ZVAL_COPY(EX_VAR(opline->result.var), &z_copy);
2419
15
  }
2420
262
  object->handlers->write_property(object, name, &z_copy, cache_slot);
2421
262
  OBJ_RELEASE(object);
2422
262
  zval_ptr_dtor(&z_copy);
2423
262
  if (z == &rv) {
2424
123
    zval_ptr_dtor(z);
2425
123
  }
2426
262
}
2427
2428
static zend_never_inline void zend_assign_op_overloaded_property(zend_object *object, zend_string *name, void **cache_slot, zval *value OPLINE_DC EXECUTE_DATA_DC)
2429
307
{
2430
307
  zval *z;
2431
307
  zval rv, res;
2432
2433
307
  GC_ADDREF(object);
2434
307
  z = object->handlers->read_property(object, name, BP_VAR_R, cache_slot, &rv);
2435
307
  if (UNEXPECTED(EG(exception))) {
2436
9
    OBJ_RELEASE(object);
2437
9
    if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2438
0
      ZVAL_UNDEF(EX_VAR(opline->result.var));
2439
0
    }
2440
9
    return;
2441
9
  }
2442
298
  if (zend_binary_op(&res, z, value OPLINE_CC) == SUCCESS) {
2443
271
    object->handlers->write_property(object, name, &res, cache_slot);
2444
271
  }
2445
298
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
2446
72
    ZVAL_COPY(EX_VAR(opline->result.var), &res);
2447
72
  }
2448
298
  if (z == &rv) {
2449
210
    zval_ptr_dtor(z);
2450
210
  }
2451
298
  zval_ptr_dtor(&res);
2452
298
  OBJ_RELEASE(object);
2453
298
}
2454
2455
/* Utility Functions for Extensions */
2456
static void zend_extension_statement_handler(const zend_extension *extension, zend_execute_data *frame)
2457
0
{
2458
0
  if (extension->statement_handler) {
2459
0
    extension->statement_handler(frame);
2460
0
  }
2461
0
}
2462
2463
2464
static void zend_extension_fcall_begin_handler(const zend_extension *extension, zend_execute_data *frame)
2465
0
{
2466
0
  if (extension->fcall_begin_handler) {
2467
0
    extension->fcall_begin_handler(frame);
2468
0
  }
2469
0
}
2470
2471
2472
static void zend_extension_fcall_end_handler(const zend_extension *extension, zend_execute_data *frame)
2473
0
{
2474
0
  if (extension->fcall_end_handler) {
2475
0
    extension->fcall_end_handler(frame);
2476
0
  }
2477
0
}
2478
2479
2480
static zend_always_inline HashTable *zend_get_target_symbol_table(int fetch_type EXECUTE_DATA_DC)
2481
61.7k
{
2482
61.7k
  HashTable *ht;
2483
2484
61.7k
  if (EXPECTED(fetch_type & (ZEND_FETCH_GLOBAL_LOCK | ZEND_FETCH_GLOBAL))) {
2485
5.11k
    ht = &EG(symbol_table);
2486
56.5k
  } else {
2487
56.5k
    ZEND_ASSERT(fetch_type & ZEND_FETCH_LOCAL);
2488
56.5k
    if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
2489
2.77k
      zend_rebuild_symbol_table();
2490
2.77k
    }
2491
56.5k
    ht = EX(symbol_table);
2492
56.5k
  }
2493
61.7k
  return ht;
2494
61.7k
}
2495
2496
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_offset(zend_long lval)
2497
2.51k
{
2498
2.51k
  zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, lval);
2499
2.51k
}
2500
2501
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_index(const zend_string *offset)
2502
2.20k
{
2503
2.20k
  zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset));
2504
2.20k
}
2505
2506
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval)
2507
391
{
2508
  /* The array may be destroyed while throwing the notice.
2509
   * Temporarily increase the refcount to detect this situation. */
2510
391
  if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2511
391
    GC_ADDREF(ht);
2512
391
  }
2513
391
  zend_undefined_offset(lval);
2514
391
  if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
2515
0
    if (!GC_REFCOUNT(ht)) {
2516
0
      zend_array_destroy(ht);
2517
0
    }
2518
0
    return NULL;
2519
0
  }
2520
391
  if (EG(exception)) {
2521
0
    return NULL;
2522
0
  }
2523
391
  return zend_hash_index_add_new(ht, lval, &EG(uninitialized_zval));
2524
391
}
2525
2526
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset)
2527
1.16k
{
2528
1.16k
  zval *retval;
2529
2530
  /* The array may be destroyed while throwing the notice.
2531
   * Temporarily increase the refcount to detect this situation. */
2532
1.16k
  if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2533
1.16k
    GC_ADDREF(ht);
2534
1.16k
  }
2535
  /* Key may be released while throwing the undefined index warning. */
2536
1.16k
  zend_string_addref(offset);
2537
1.16k
  zend_undefined_index(offset);
2538
1.16k
  if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
2539
0
    if (!GC_REFCOUNT(ht)) {
2540
0
      zend_array_destroy(ht);
2541
0
    }
2542
0
    retval = NULL;
2543
1.16k
  } else if (EG(exception)) {
2544
0
    retval = NULL;
2545
1.16k
  } else {
2546
1.16k
    retval = zend_hash_add_new(ht, offset, &EG(uninitialized_zval));
2547
1.16k
  }
2548
1.16k
  zend_string_release(offset);
2549
1.16k
  return retval;
2550
1.16k
}
2551
2552
ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method)
2553
425
{
2554
425
  zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method));
2555
425
}
2556
2557
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_invalid_method_call(zval *object, zval *function_name)
2558
460
{
2559
460
  zend_throw_error(NULL, "Call to a member function %s() on %s",
2560
460
    Z_STRVAL_P(function_name), zend_zval_value_name(object));
2561
460
}
2562
2563
ZEND_API void ZEND_FASTCALL zend_non_static_method_call(const zend_function *fbc)
2564
64
{
2565
64
  zend_throw_error(
2566
64
    zend_ce_error,
2567
64
    "Non-static method %s::%s() cannot be called statically",
2568
64
    ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2569
64
}
2570
2571
ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num)
2572
347
{
2573
347
  const char *arg_name = get_function_arg_name(func, arg_num);
2574
2575
347
  zend_error(E_WARNING, "%s%s%s(): Argument #%d%s%s%s must be passed by reference, value given",
2576
347
    func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
2577
347
    func->common.scope ? "::" : "",
2578
347
    ZSTR_VAL(func->common.function_name),
2579
347
    arg_num,
2580
347
    arg_name ? " ($" : "",
2581
347
    arg_name ? arg_name : "",
2582
347
    arg_name ? ")" : ""
2583
347
  );
2584
347
}
2585
2586
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(void)
2587
245
{
2588
245
  zend_throw_error(NULL, "Cannot use a scalar value as an array");
2589
245
}
2590
2591
ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void)
2592
139
{
2593
139
  zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
2594
139
}
2595
2596
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
2597
0
{
2598
0
  zend_error(E_WARNING,
2599
0
    "Resource ID#" ZEND_LONG_FMT " used as offset, casting to integer (" ZEND_LONG_FMT ")",
2600
0
    Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
2601
0
}
2602
2603
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_string(void)
2604
32
{
2605
32
  zend_throw_error(NULL, "[] operator not supported for strings");
2606
32
}
2607
2608
#ifdef ZEND_CHECK_STACK_LIMIT
2609
ZEND_API zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_call_stack_size_error(void)
2610
1
{
2611
1
  size_t max_stack_size = 0;
2612
1
  if ((uintptr_t) EG(stack_base) > (uintptr_t) EG(stack_limit)) {
2613
1
    max_stack_size = (size_t) ((uintptr_t) EG(stack_base) - (uintptr_t) EG(stack_limit));
2614
1
  }
2615
2616
1
  zend_throw_error(NULL, "Maximum call stack size of %zu bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion?",
2617
1
    max_stack_size);
2618
1
}
2619
#endif /* ZEND_CHECK_STACK_LIMIT */
2620
2621
static ZEND_COLD void zend_binary_assign_op_dim_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC)
2622
22
{
2623
22
  if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
2624
12
    if (opline->op2_type == IS_UNUSED) {
2625
4
      zend_use_new_element_for_string();
2626
8
    } else {
2627
8
      zend_check_string_offset(dim, BP_VAR_RW EXECUTE_DATA_CC);
2628
8
      zend_wrong_string_offset_error();
2629
8
    }
2630
12
  } else {
2631
10
    zend_use_scalar_as_array();
2632
10
  }
2633
22
}
2634
2635
static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC)
2636
943
{
2637
943
  switch (Z_TYPE_P(dim)) {
2638
288
    case IS_UNDEF: {
2639
      /* The array may be destroyed while throwing the notice.
2640
       * Temporarily increase the refcount to detect this situation. */
2641
288
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2642
267
        GC_ADDREF(ht);
2643
267
      }
2644
288
      ZVAL_UNDEFINED_OP2();
2645
288
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
2646
0
        zend_array_destroy(ht);
2647
0
        return IS_NULL;
2648
0
      }
2649
288
      if (EG(exception)) {
2650
0
        return IS_NULL;
2651
0
      }
2652
288
      ZEND_FALLTHROUGH;
2653
288
    }
2654
574
    case IS_NULL:
2655
      /* The array may be destroyed while throwing the notice.
2656
       * Temporarily increase the refcount to detect this situation. */
2657
574
      GC_TRY_ADDREF(ht);
2658
2659
574
      zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
2660
2661
574
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
2662
0
        zend_array_destroy(ht);
2663
0
        return IS_NULL;
2664
0
      }
2665
2666
574
      if (EG(exception)) {
2667
0
        return IS_NULL;
2668
0
      }
2669
2670
574
      value->str = ZSTR_EMPTY_ALLOC();
2671
574
      return IS_STRING;
2672
217
    case IS_DOUBLE:
2673
      /* The array may be destroyed while throwing the notice.
2674
       * Temporarily increase the refcount to detect this situation. */
2675
217
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2676
155
        GC_ADDREF(ht);
2677
155
      }
2678
217
      value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
2679
217
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
2680
0
        zend_array_destroy(ht);
2681
0
        return IS_NULL;
2682
0
      }
2683
217
      if (EG(exception)) {
2684
0
        return IS_NULL;
2685
0
      }
2686
217
      return IS_LONG;
2687
0
    case IS_RESOURCE:
2688
      /* The array may be destroyed while throwing the notice.
2689
       * Temporarily increase the refcount to detect this situation. */
2690
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2691
0
        GC_ADDREF(ht);
2692
0
      }
2693
0
      zend_use_resource_as_offset(dim);
2694
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
2695
0
        zend_array_destroy(ht);
2696
0
        return IS_NULL;
2697
0
      }
2698
0
      if (EG(exception)) {
2699
0
        return IS_NULL;
2700
0
      }
2701
0
      value->lval = Z_RES_HANDLE_P(dim);
2702
0
      return IS_LONG;
2703
47
    case IS_FALSE:
2704
47
      value->lval = 0;
2705
47
      return IS_LONG;
2706
94
    case IS_TRUE:
2707
94
      value->lval = 1;
2708
94
      return IS_LONG;
2709
11
    default:
2710
11
      zend_illegal_array_offset_access(dim);
2711
11
      return IS_NULL;
2712
943
  }
2713
943
}
2714
2715
static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval *dim, zend_value *value EXECUTE_DATA_DC)
2716
10.9k
{
2717
10.9k
  switch (Z_TYPE_P(dim)) {
2718
8.56k
    case IS_UNDEF: {
2719
      /* The array may be destroyed while throwing the notice.
2720
       * Temporarily increase the refcount to detect this situation. */
2721
8.56k
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2722
8.56k
        GC_ADDREF(ht);
2723
8.56k
      }
2724
8.56k
      ZVAL_UNDEFINED_OP2();
2725
8.56k
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
2726
0
        if (!GC_REFCOUNT(ht)) {
2727
0
          zend_array_destroy(ht);
2728
0
        }
2729
0
        return IS_NULL;
2730
0
      }
2731
8.56k
      if (EG(exception)) {
2732
0
        return IS_NULL;
2733
0
      }
2734
8.56k
      ZEND_FALLTHROUGH;
2735
8.56k
    }
2736
9.96k
    case IS_NULL:
2737
      /* The array may be destroyed while throwing the notice.
2738
       * Temporarily increase the refcount to detect this situation. */
2739
9.96k
      GC_TRY_ADDREF(ht);
2740
2741
9.96k
      zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
2742
2743
9.96k
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
2744
0
        if (!GC_REFCOUNT(ht)) {
2745
0
          zend_array_destroy(ht);
2746
0
        }
2747
0
        return IS_NULL;
2748
0
      }
2749
9.96k
      if (EG(exception)) {
2750
0
        return IS_NULL;
2751
0
      }
2752
9.96k
      value->str = ZSTR_EMPTY_ALLOC();
2753
9.96k
      return IS_STRING;
2754
321
    case IS_DOUBLE:
2755
      /* The array may be destroyed while throwing the notice.
2756
       * Temporarily increase the refcount to detect this situation. */
2757
321
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2758
321
        GC_ADDREF(ht);
2759
321
      }
2760
321
      value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
2761
321
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
2762
0
        if (!GC_REFCOUNT(ht)) {
2763
0
          zend_array_destroy(ht);
2764
0
        }
2765
0
        return IS_NULL;
2766
0
      }
2767
321
      if (EG(exception)) {
2768
0
        return IS_NULL;
2769
0
      }
2770
321
      return IS_LONG;
2771
0
    case IS_RESOURCE:
2772
      /* The array may be destroyed while throwing the notice.
2773
       * Temporarily increase the refcount to detect this situation. */
2774
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
2775
0
        GC_ADDREF(ht);
2776
0
      }
2777
0
      zend_use_resource_as_offset(dim);
2778
0
      if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) {
2779
0
        if (!GC_REFCOUNT(ht)) {
2780
0
          zend_array_destroy(ht);
2781
0
        }
2782
0
        return IS_NULL;
2783
0
      }
2784
0
      if (EG(exception)) {
2785
0
        return IS_NULL;
2786
0
      }
2787
0
      value->lval = Z_RES_HANDLE_P(dim);
2788
0
      return IS_LONG;
2789
43
    case IS_FALSE:
2790
43
      value->lval = 0;
2791
43
      return IS_LONG;
2792
463
    case IS_TRUE:
2793
463
      value->lval = 1;
2794
463
      return IS_LONG;
2795
111
    default:
2796
111
      zend_illegal_array_offset_access(dim);
2797
111
      return IS_NULL;
2798
10.9k
  }
2799
10.9k
}
2800
2801
static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int dim_type, int type EXECUTE_DATA_DC)
2802
72.5k
{
2803
72.5k
  zval *retval = NULL;
2804
72.5k
  zend_string *offset_key;
2805
72.5k
  zend_ulong hval;
2806
2807
72.5k
try_again:
2808
72.5k
  if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
2809
44.5k
    hval = Z_LVAL_P(dim);
2810
46.1k
num_index:
2811
46.1k
    if (type != BP_VAR_W) {
2812
14.1k
      ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef);
2813
12.4k
      return retval;
2814
1.62k
num_undef:
2815
1.62k
      switch (type) {
2816
1.14k
        case BP_VAR_R:
2817
1.14k
          zend_undefined_offset(hval);
2818
1.14k
          ZEND_FALLTHROUGH;
2819
1.14k
        case BP_VAR_UNSET:
2820
1.22k
        case BP_VAR_IS:
2821
1.22k
          retval = &EG(uninitialized_zval);
2822
1.22k
          break;
2823
391
        case BP_VAR_RW:
2824
391
          retval = zend_undefined_offset_write(ht, hval);
2825
391
          break;
2826
1.62k
        }
2827
31.9k
    } else {
2828
31.9k
      ZEND_HASH_INDEX_LOOKUP(ht, hval, retval);
2829
31.9k
    }
2830
46.1k
  } else if (EXPECTED(Z_TYPE_P(dim) == IS_STRING)) {
2831
16.1k
    offset_key = Z_STR_P(dim);
2832
16.1k
    if (ZEND_CONST_COND(dim_type != IS_CONST, 1)) {
2833
16.1k
      if (ZEND_HANDLE_NUMERIC(offset_key, hval)) {
2834
383
        goto num_index;
2835
383
      }
2836
16.1k
    }
2837
26.3k
str_index:
2838
26.3k
    if (type != BP_VAR_W) {
2839
10.6k
      retval = zend_hash_find_ex(ht, offset_key, ZEND_CONST_COND(dim_type == IS_CONST, 0));
2840
10.6k
      if (!retval) {
2841
2.65k
        switch (type) {
2842
1.04k
          case BP_VAR_R:
2843
1.04k
            zend_undefined_index(offset_key);
2844
1.04k
            ZEND_FALLTHROUGH;
2845
1.05k
          case BP_VAR_UNSET:
2846
1.49k
          case BP_VAR_IS:
2847
1.49k
            retval = &EG(uninitialized_zval);
2848
1.49k
            break;
2849
1.16k
          case BP_VAR_RW:
2850
1.16k
            retval = zend_undefined_index_write(ht, offset_key);
2851
1.16k
            break;
2852
2.65k
        }
2853
2.65k
      }
2854
15.6k
    } else {
2855
15.6k
      retval = zend_hash_lookup(ht, offset_key);
2856
15.6k
    }
2857
26.3k
  } else if (EXPECTED(Z_TYPE_P(dim) == IS_REFERENCE)) {
2858
2
    dim = Z_REFVAL_P(dim);
2859
2
    goto try_again;
2860
11.8k
  } else {
2861
11.8k
    zend_value val;
2862
11.8k
    uint8_t t;
2863
2864
11.8k
    if (type != BP_VAR_W && type != BP_VAR_RW) {
2865
943
      t = slow_index_convert(ht, dim, &val EXECUTE_DATA_CC);
2866
10.9k
    } else {
2867
10.9k
      t = slow_index_convert_w(ht, dim, &val EXECUTE_DATA_CC);
2868
10.9k
    }
2869
11.8k
    if (t == IS_STRING) {
2870
10.5k
      offset_key = val.str;
2871
10.5k
      goto str_index;
2872
10.5k
    } else if (t == IS_LONG) {
2873
1.18k
      hval = val.lval;
2874
1.18k
      goto num_index;
2875
1.18k
    } else {
2876
122
      retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
2877
122
          NULL : &EG(uninitialized_zval);
2878
122
    }
2879
11.8k
  }
2880
60.0k
  return retval;
2881
72.5k
}
2882
2883
static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W(HashTable *ht, const zval *dim EXECUTE_DATA_DC)
2884
22.8k
{
2885
22.8k
  return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_W EXECUTE_DATA_CC);
2886
22.8k
}
2887
2888
static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_W_CONST(HashTable *ht, const zval *dim EXECUTE_DATA_DC)
2889
5.83k
{
2890
5.83k
  return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_W EXECUTE_DATA_CC);
2891
5.83k
}
2892
2893
static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW(HashTable *ht, const zval *dim EXECUTE_DATA_DC)
2894
3.13k
{
2895
3.13k
  return zend_fetch_dimension_address_inner(ht, dim, IS_TMP_VAR, BP_VAR_RW EXECUTE_DATA_CC);
2896
3.13k
}
2897
2898
static zend_never_inline zval* ZEND_FASTCALL zend_fetch_dimension_address_inner_RW_CONST(HashTable *ht, const zval *dim EXECUTE_DATA_DC)
2899
2.76k
{
2900
2.76k
  return zend_fetch_dimension_address_inner(ht, dim, IS_CONST, BP_VAR_RW EXECUTE_DATA_CC);
2901
2.76k
}
2902
2903
static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *container, zval *dim, int dim_type, int type EXECUTE_DATA_DC)
2904
23.5k
{
2905
23.5k
  zval *retval;
2906
2907
23.5k
  if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
2908
19.5k
try_array:
2909
19.5k
    SEPARATE_ARRAY(container);
2910
22.2k
fetch_from_array:
2911
22.2k
    if (dim == NULL) {
2912
2.01k
      retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
2913
2.01k
      if (UNEXPECTED(retval == NULL)) {
2914
37
        zend_cannot_add_element();
2915
37
        ZVAL_UNDEF(result);
2916
37
        return;
2917
37
      }
2918
20.2k
    } else {
2919
20.2k
      retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC);
2920
20.2k
      if (UNEXPECTED(!retval)) {
2921
        /* This may fail without throwing if the array was modified while throwing an
2922
         * undefined index error. */
2923
21
        ZVAL_NULL(result);
2924
21
        return;
2925
21
      }
2926
20.2k
    }
2927
22.2k
    ZVAL_INDIRECT(result, retval);
2928
22.2k
    return;
2929
22.2k
  } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) {
2930
4.16k
    zend_reference *ref = Z_REF_P(container);
2931
4.16k
    container = Z_REFVAL_P(container);
2932
4.16k
    if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
2933
3.83k
      goto try_array;
2934
3.83k
    } else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
2935
293
      if (type != BP_VAR_UNSET) {
2936
293
        if (ZEND_REF_HAS_TYPE_SOURCES(ref)) {
2937
5
          if (UNEXPECTED(!zend_verify_ref_array_assignable(ref))) {
2938
5
            ZVAL_UNDEF(result);
2939
5
            return;
2940
5
          }
2941
5
        }
2942
288
        array_init(container);
2943
288
        goto fetch_from_array;
2944
293
      } else {
2945
0
        goto return_null;
2946
0
      }
2947
293
    }
2948
4.16k
  }
2949
3.63k
  if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
2950
150
    if (dim == NULL) {
2951
4
      zend_use_new_element_for_string();
2952
146
    } else {
2953
146
      zend_check_string_offset(dim, type EXECUTE_DATA_CC);
2954
146
      zend_wrong_string_offset_error();
2955
146
    }
2956
150
    ZVAL_UNDEF(result);
2957
3.48k
  } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
2958
845
    zend_object *obj = Z_OBJ_P(container);
2959
845
    GC_ADDREF(obj);
2960
845
    if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
2961
0
      dim = ZVAL_UNDEFINED_OP2();
2962
845
    } else if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
2963
0
      dim++;
2964
0
    }
2965
845
    retval = obj->handlers->read_dimension(obj, dim, type, result);
2966
2967
845
    if (UNEXPECTED(retval == &EG(uninitialized_zval))) {
2968
0
      zend_class_entry *ce = obj->ce;
2969
2970
0
      ZVAL_NULL(result);
2971
0
      zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
2972
845
    } else if (EXPECTED(retval && Z_TYPE_P(retval) != IS_UNDEF)) {
2973
822
      if (!Z_ISREF_P(retval)) {
2974
516
        if (result != retval) {
2975
501
          ZVAL_COPY(result, retval);
2976
501
          retval = result;
2977
501
        }
2978
516
        if (Z_TYPE_P(retval) != IS_OBJECT) {
2979
321
          zend_class_entry *ce = obj->ce;
2980
321
          zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ZSTR_VAL(ce->name));
2981
321
        }
2982
516
      } else if (UNEXPECTED(Z_REFCOUNT_P(retval) == 1)) {
2983
215
        ZVAL_UNREF(retval);
2984
215
      }
2985
822
      if (result != retval) {
2986
206
        ZVAL_INDIRECT(result, retval);
2987
206
      }
2988
822
    } else {
2989
23
      ZEND_ASSERT(EG(exception) && "read_dimension() returned NULL without exception");
2990
23
      ZVAL_UNDEF(result);
2991
23
    }
2992
845
    if (UNEXPECTED(GC_DELREF(obj) == 0)) {
2993
0
      zend_objects_store_del(obj);
2994
0
    }
2995
2.63k
  } else {
2996
2.63k
    if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
2997
2.52k
      if (type != BP_VAR_W && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
2998
199
        ZVAL_UNDEFINED_OP1();
2999
199
      }
3000
2.52k
      if (type != BP_VAR_UNSET) {
3001
2.42k
        HashTable *ht = zend_new_array(0);
3002
2.42k
        uint8_t old_type = Z_TYPE_P(container);
3003
3004
2.42k
        ZVAL_ARR(container, ht);
3005
2.42k
        if (UNEXPECTED(old_type == IS_FALSE)) {
3006
146
          GC_ADDREF(ht);
3007
146
          zend_false_to_array_deprecated();
3008
146
          if (UNEXPECTED(GC_DELREF(ht) == 0)) {
3009
0
            zend_array_destroy(ht);
3010
0
            goto return_null;
3011
0
          }
3012
146
        }
3013
2.42k
        goto fetch_from_array;
3014
2.42k
      } else {
3015
102
        if (UNEXPECTED(Z_TYPE_P(container) == IS_FALSE)) {
3016
13
          zend_false_to_array_deprecated();
3017
13
        }
3018
102
return_null:
3019
        /* for read-mode only */
3020
102
        if (ZEND_CONST_COND(dim_type == IS_CV, dim != NULL) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
3021
2
          ZVAL_UNDEFINED_OP2();
3022
2
        }
3023
102
        ZVAL_NULL(result);
3024
102
      }
3025
2.52k
    } else {
3026
108
      if (type == BP_VAR_UNSET) {
3027
15
        zend_throw_error(NULL, "Cannot unset offset in a non-array variable");
3028
15
        ZVAL_UNDEF(result);
3029
93
      } else {
3030
93
        zend_use_scalar_as_array();
3031
93
        ZVAL_UNDEF(result);
3032
93
      }
3033
108
    }
3034
2.63k
  }
3035
3.63k
}
3036
3037
static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_W(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC)
3038
22.0k
{
3039
22.0k
  zval *result = EX_VAR(opline->result.var);
3040
22.0k
  zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_W EXECUTE_DATA_CC);
3041
22.0k
}
3042
3043
static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_RW(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC)
3044
1.23k
{
3045
1.23k
  zval *result = EX_VAR(opline->result.var);
3046
1.23k
  zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_RW EXECUTE_DATA_CC);
3047
1.23k
}
3048
3049
static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_UNSET(zval *container_ptr, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC)
3050
241
{
3051
241
  zval *result = EX_VAR(opline->result.var);
3052
241
  zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_UNSET EXECUTE_DATA_CC);
3053
241
}
3054
3055
static zend_always_inline void zend_fetch_dimension_address_read(zval *result, zval *container, zval *dim, int dim_type, int type, bool is_list, bool slow EXECUTE_DATA_DC)
3056
19.4k
{
3057
19.4k
  zval *retval;
3058
3059
19.4k
  if (!slow) {
3060
8.38k
    if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
3061
6.20k
try_array:
3062
6.20k
      retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type EXECUTE_DATA_CC);
3063
6.20k
      ZVAL_COPY_DEREF(result, retval);
3064
6.20k
      return;
3065
6.17k
    } else if (EXPECTED(Z_TYPE_P(container) == IS_REFERENCE)) {
3066
86
      container = Z_REFVAL_P(container);
3067
86
      if (EXPECTED(Z_TYPE_P(container) == IS_ARRAY)) {
3068
24
        goto try_array;
3069
24
      }
3070
86
    }
3071
8.38k
  }
3072
13.2k
  if (!is_list && EXPECTED(Z_TYPE_P(container) == IS_STRING)) {
3073
2.97k
    zend_string *str = Z_STR_P(container);
3074
2.97k
    zend_long offset;
3075
3076
2.97k
try_string_offset:
3077
2.97k
    if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
3078
971
      switch (Z_TYPE_P(dim)) {
3079
467
        case IS_STRING:
3080
467
        {
3081
467
          bool trailing_data = false;
3082
          /* For BC reasons we allow errors so that we can warn on leading numeric string */
3083
467
          if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset,
3084
467
              NULL, /* allow errors */ true, NULL, &trailing_data)) {
3085
254
            if (UNEXPECTED(trailing_data)) {
3086
114
              zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
3087
114
            }
3088
254
            goto out;
3089
254
          }
3090
213
          if (type == BP_VAR_IS) {
3091
60
            ZVAL_NULL(result);
3092
60
            return;
3093
60
          }
3094
153
          zend_illegal_string_offset(dim, BP_VAR_R);
3095
153
          ZVAL_NULL(result);
3096
153
          return;
3097
213
        }
3098
40
        case IS_UNDEF:
3099
          /* The string may be destroyed while throwing the notice.
3100
           * Temporarily increase the refcount to detect this situation. */
3101
40
          if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
3102
0
            GC_ADDREF(str);
3103
0
          }
3104
40
          ZVAL_UNDEFINED_OP2();
3105
40
          if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
3106
0
            zend_string_efree(str);
3107
0
            ZVAL_NULL(result);
3108
0
            return;
3109
0
          }
3110
40
          ZEND_FALLTHROUGH;
3111
408
        case IS_DOUBLE:
3112
426
        case IS_NULL:
3113
458
        case IS_FALSE:
3114
476
        case IS_TRUE:
3115
476
          if (type != BP_VAR_IS) {
3116
            /* The string may be destroyed while throwing the notice.
3117
             * Temporarily increase the refcount to detect this situation. */
3118
462
            if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
3119
4
              GC_ADDREF(str);
3120
4
            }
3121
462
            zend_error(E_WARNING, "String offset cast occurred");
3122
462
            if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
3123
0
              zend_string_efree(str);
3124
0
              ZVAL_NULL(result);
3125
0
              return;
3126
0
            }
3127
462
          }
3128
          /* To prevent double warning */
3129
476
          if (Z_TYPE_P(dim) == IS_DOUBLE) {
3130
368
            offset = zend_dval_to_lval_silent(Z_DVAL_P(dim));
3131
368
            goto out;
3132
368
          }
3133
108
          break;
3134
108
        case IS_REFERENCE:
3135
0
          dim = Z_REFVAL_P(dim);
3136
0
          goto try_string_offset;
3137
28
        default:
3138
28
          zend_illegal_string_offset(dim, BP_VAR_R);
3139
28
          ZVAL_NULL(result);
3140
28
          return;
3141
971
      }
3142
3143
108
      offset = zval_get_long_func(dim, /* is_strict */ false);
3144
2.00k
    } else {
3145
2.00k
      offset = Z_LVAL_P(dim);
3146
2.00k
    }
3147
2.73k
    out:
3148
3149
2.73k
    if (UNEXPECTED(ZSTR_LEN(str) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) {
3150
1.05k
      if (type != BP_VAR_IS) {
3151
1.03k
        zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
3152
1.03k
        ZVAL_EMPTY_STRING(result);
3153
1.03k
      } else {
3154
23
        ZVAL_NULL(result);
3155
23
      }
3156
1.68k
    } else {
3157
1.68k
      zend_uchar c;
3158
1.68k
      zend_long real_offset;
3159
3160
1.68k
      real_offset = (UNEXPECTED(offset < 0)) /* Handle negative offset */
3161
1.68k
        ? (zend_long)ZSTR_LEN(str) + offset : offset;
3162
1.68k
      c = (zend_uchar)ZSTR_VAL(str)[real_offset];
3163
3164
1.68k
      ZVAL_CHAR(result, c);
3165
1.68k
    }
3166
10.2k
  } else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
3167
2.13k
    zend_object *obj = Z_OBJ_P(container);
3168
3169
2.13k
    GC_ADDREF(obj);
3170
2.13k
    if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
3171
0
      dim = ZVAL_UNDEFINED_OP2();
3172
0
    }
3173
2.13k
    if (dim_type == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
3174
5
      dim++;
3175
5
    }
3176
2.13k
    retval = obj->handlers->read_dimension(obj, dim, type, result);
3177
3178
2.13k
    ZEND_ASSERT(result != NULL);
3179
2.13k
    if (retval) {
3180
1.59k
      if (result != retval) {
3181
1.13k
        ZVAL_COPY_DEREF(result, retval);
3182
1.13k
      } else if (UNEXPECTED(Z_ISREF_P(retval))) {
3183
102
        zend_unwrap_reference(result);
3184
102
      }
3185
1.59k
    } else {
3186
44
      ZVAL_NULL(result);
3187
44
    }
3188
1.63k
    if (UNEXPECTED(GC_DELREF(obj) == 0)) {
3189
5
      zend_objects_store_del(obj);
3190
5
    }
3191
8.09k
  } else {
3192
8.09k
    if (type != BP_VAR_IS && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
3193
4.61k
      container = ZVAL_UNDEFINED_OP1();
3194
4.61k
    }
3195
8.09k
    if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) {
3196
1.20k
      ZVAL_UNDEFINED_OP2();
3197
1.20k
    }
3198
8.09k
    if (is_list && Z_TYPE_P(container) > IS_NULL) {
3199
173
      zend_error(E_WARNING, "Cannot use %s as array", zend_zval_type_name(container));
3200
173
    }
3201
8.09k
    if (!is_list && type != BP_VAR_IS) {
3202
6.94k
      zend_error(E_WARNING, "Trying to access array offset on %s",
3203
6.94k
        zend_zval_value_name(container));
3204
6.94k
    }
3205
8.09k
    ZVAL_NULL(result);
3206
8.09k
  }
3207
13.2k
}
3208
3209
static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_read_R(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC)
3210
1.14k
{
3211
1.14k
  zval *result = EX_VAR(opline->result.var);
3212
1.14k
  zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 0, 0 EXECUTE_DATA_CC);
3213
1.14k
}
3214
3215
static zend_never_inline void zend_fetch_dimension_address_read_R_slow(zval *container, zval *dim OPLINE_DC EXECUTE_DATA_DC)
3216
11.0k
{
3217
11.0k
  zval *result = EX_VAR(opline->result.var);
3218
11.0k
  zend_fetch_dimension_address_read(result, container, dim, IS_CV, BP_VAR_R, 0, 1 EXECUTE_DATA_CC);
3219
11.0k
}
3220
3221
static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_read_IS(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC)
3222
2.84k
{
3223
2.84k
  zval *result = EX_VAR(opline->result.var);
3224
2.84k
  zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_IS, 0, 0 EXECUTE_DATA_CC);
3225
2.84k
}
3226
3227
static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_LIST_r(zval *container, zval *dim, int dim_type OPLINE_DC EXECUTE_DATA_DC)
3228
4.09k
{
3229
4.09k
  zval *result = EX_VAR(opline->result.var);
3230
4.09k
  zend_fetch_dimension_address_read(result, container, dim, dim_type, BP_VAR_R, 1, 0 EXECUTE_DATA_CC);
3231
4.09k
}
3232
3233
ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *dim, int type)
3234
298
{
3235
298
  zend_fetch_dimension_address_read(result, container, dim, IS_TMP_VAR, type, 0, 0 NO_EXECUTE_DATA_CC);
3236
298
}
3237
3238
static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable *ht, zval *offset EXECUTE_DATA_DC)
3239
446
{
3240
446
  zend_ulong hval;
3241
3242
446
  if (Z_TYPE_P(offset) == IS_DOUBLE) {
3243
    /* The array may be destroyed while throwing a warning in case the float is not representable as an int.
3244
     * Temporarily increase the refcount to detect this situation. */
3245
10
    GC_TRY_ADDREF(ht);
3246
10
    hval = zend_dval_to_lval_safe(Z_DVAL_P(offset));
3247
10
    if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
3248
0
      zend_array_destroy(ht);
3249
0
      return NULL;
3250
0
    }
3251
10
    if (EG(exception)) {
3252
0
      return NULL;
3253
0
    }
3254
20
num_idx:
3255
20
    return zend_hash_index_find(ht, hval);
3256
436
  } else if (Z_TYPE_P(offset) == IS_NULL) {
3257
393
null_undef_idx:
3258
    /* The array may be destroyed while throwing the notice.
3259
     * Temporarily increase the refcount to detect this situation. */
3260
393
    GC_TRY_ADDREF(ht);
3261
3262
393
    zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
3263
3264
393
    if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
3265
0
      zend_array_destroy(ht);
3266
0
      return NULL;
3267
0
    }
3268
3269
393
    if (EG(exception)) {
3270
0
      return NULL;
3271
0
    }
3272
3273
393
    return zend_hash_find_known_hash(ht, ZSTR_EMPTY_ALLOC());
3274
431
  } else if (Z_TYPE_P(offset) == IS_FALSE) {
3275
5
    hval = 0;
3276
5
    goto num_idx;
3277
426
  } else if (Z_TYPE_P(offset) == IS_TRUE) {
3278
5
    hval = 1;
3279
5
    goto num_idx;
3280
421
  } else if (Z_TYPE_P(offset) == IS_RESOURCE) {
3281
0
    zend_use_resource_as_offset(offset);
3282
0
    hval = Z_RES_HANDLE_P(offset);
3283
0
    goto num_idx;
3284
421
  } else if (/*OP2_TYPE == IS_CV &&*/ Z_TYPE_P(offset) == IS_UNDEF) {
3285
388
    ZVAL_UNDEFINED_OP2();
3286
388
    goto null_undef_idx;
3287
388
  } else {
3288
33
    zend_illegal_array_offset_isset(offset);
3289
33
    return NULL;
3290
33
  }
3291
446
}
3292
3293
static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC)
3294
1.62k
{
3295
1.62k
  if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
3296
17
    offset = ZVAL_UNDEFINED_OP2();
3297
17
  }
3298
3299
1.62k
  if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
3300
370
    return Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 0);
3301
1.25k
  } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
3302
452
    zend_long lval;
3303
3304
452
    if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
3305
135
      lval = Z_LVAL_P(offset);
3306
329
str_offset:
3307
329
      if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
3308
57
        lval += (zend_long)Z_STRLEN_P(container);
3309
57
      }
3310
329
      if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3311
250
        return 1;
3312
250
      } else {
3313
79
        return 0;
3314
79
      }
3315
329
    } else {
3316
      /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/
3317
317
        ZVAL_DEREF(offset);
3318
      /*}*/
3319
317
      if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
3320
255
          || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
3321
235
            && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
3322
194
        lval = zval_get_long_ex(offset, /* is_strict */ true);
3323
194
        goto str_offset;
3324
194
      }
3325
123
      return 0;
3326
317
    }
3327
803
  } else {
3328
803
    return 0;
3329
803
  }
3330
1.62k
}
3331
3332
static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *container, zval *offset EXECUTE_DATA_DC)
3333
532
{
3334
532
  if (/*OP2_TYPE == IS_CV &&*/ UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
3335
5
    offset = ZVAL_UNDEFINED_OP2();
3336
5
  }
3337
3338
532
  if (/*OP1_TYPE != IS_CONST &&*/ EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
3339
64
    return !Z_OBJ_HT_P(container)->has_dimension(Z_OBJ_P(container), offset, 1);
3340
468
  } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
3341
411
    zend_long lval;
3342
3343
411
    if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
3344
133
      lval = Z_LVAL_P(offset);
3345
312
str_offset:
3346
312
      if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
3347
89
        lval += (zend_long)Z_STRLEN_P(container);
3348
89
      }
3349
312
      if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3350
246
        return (Z_STRVAL_P(container)[lval] == '0');
3351
246
      } else {
3352
66
        return 1;
3353
66
      }
3354
312
    } else {
3355
      /*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/
3356
278
        ZVAL_DEREF(offset);
3357
      /*}*/
3358
278
      if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
3359
163
          || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
3360
179
            && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
3361
179
        lval = zval_get_long_ex(offset, /* is_strict */ true);
3362
179
        goto str_offset;
3363
179
      }
3364
99
      return 1;
3365
278
    }
3366
411
  } else {
3367
57
    return 1;
3368
57
  }
3369
532
}
3370
3371
static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable *ht, zval *key OPLINE_DC EXECUTE_DATA_DC)
3372
346
{
3373
346
  zend_string *str;
3374
346
  zend_ulong hval;
3375
3376
346
try_again:
3377
346
  if (EXPECTED(Z_TYPE_P(key) == IS_STRING)) {
3378
171
    str = Z_STR_P(key);
3379
171
    if (ZEND_HANDLE_NUMERIC(str, hval)) {
3380
0
      goto num_key;
3381
0
    }
3382
180
str_key:
3383
180
    return zend_hash_exists(ht, str);
3384
175
  } else if (EXPECTED(Z_TYPE_P(key) == IS_LONG)) {
3385
161
    hval = Z_LVAL_P(key);
3386
166
num_key:
3387
166
    return zend_hash_index_exists(ht, hval);
3388
161
  } else if (EXPECTED(Z_ISREF_P(key))) {
3389
0
    key = Z_REFVAL_P(key);
3390
0
    goto try_again;
3391
14
  } else if (Z_TYPE_P(key) == IS_DOUBLE) {
3392
    /* The array may be destroyed while throwing a warning in case the float is not representable as an int.
3393
     * Temporarily increase the refcount to detect this situation. */
3394
5
    GC_TRY_ADDREF(ht);
3395
5
    hval = zend_dval_to_lval_safe(Z_DVAL_P(key));
3396
5
    if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
3397
0
      zend_array_destroy(ht);
3398
0
      return false;
3399
0
    }
3400
5
    if (EG(exception)) {
3401
0
      return false;
3402
0
    }
3403
5
    goto num_key;
3404
9
  } else if (Z_TYPE_P(key) == IS_FALSE) {
3405
0
    hval = 0;
3406
0
    goto num_key;
3407
9
  } else if (Z_TYPE_P(key) == IS_TRUE) {
3408
0
    hval = 1;
3409
0
    goto num_key;
3410
9
  } else if (Z_TYPE_P(key) == IS_RESOURCE) {
3411
0
    zend_use_resource_as_offset(key);
3412
0
    hval = Z_RES_HANDLE_P(key);
3413
0
    goto num_key;
3414
9
  } else if (Z_TYPE_P(key) <= IS_NULL) {
3415
9
    if (UNEXPECTED(Z_TYPE_P(key) == IS_UNDEF)) {
3416
0
      ZVAL_UNDEFINED_OP1();
3417
9
    } else {
3418
9
      ZEND_ASSERT(Z_TYPE_P(key) == IS_NULL);
3419
9
      zend_error(E_DEPRECATED, "Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead");
3420
9
    }
3421
9
    str = ZSTR_EMPTY_ALLOC();
3422
9
    goto str_key;
3423
9
  } else {
3424
0
    zend_illegal_array_offset_access(key);
3425
0
    return 0;
3426
0
  }
3427
346
}
3428
3429
static ZEND_COLD void ZEND_FASTCALL zend_array_key_exists_error(
3430
    zval *subject, zval *key OPLINE_DC EXECUTE_DATA_DC)
3431
16
{
3432
16
  if (Z_TYPE_P(key) == IS_UNDEF) {
3433
0
    ZVAL_UNDEFINED_OP1();
3434
0
  }
3435
16
  if (Z_TYPE_P(subject) == IS_UNDEF) {
3436
5
    ZVAL_UNDEFINED_OP2();
3437
5
  }
3438
16
  if (!EG(exception)) {
3439
16
    zend_type_error("array_key_exists(): Argument #2 ($array) must be of type array, %s given",
3440
16
      zend_zval_value_name(subject));
3441
16
  }
3442
16
}
3443
3444
115
static zend_always_inline bool promotes_to_array(zval *val) {
3445
115
  return Z_TYPE_P(val) <= IS_FALSE
3446
69
    || (Z_ISREF_P(val) && Z_TYPE_P(Z_REFVAL_P(val)) <= IS_FALSE);
3447
115
}
3448
3449
61
static zend_always_inline bool check_type_array_assignable(zend_type type) {
3450
61
  if (!ZEND_TYPE_IS_SET(type)) {
3451
0
    return 1;
3452
0
  }
3453
61
  return (ZEND_TYPE_FULL_MASK(type) & MAY_BE_ARRAY) != 0;
3454
61
}
3455
3456
/* Checks whether an array can be assigned to the reference. Throws error if not assignable. */
3457
15
ZEND_API bool zend_verify_ref_array_assignable(zend_reference *ref) {
3458
15
  zend_property_info *prop;
3459
15
  ZEND_ASSERT(ZEND_REF_HAS_TYPE_SOURCES(ref));
3460
45
  ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
3461
45
    if (!check_type_array_assignable(prop->type)) {
3462
10
      zend_throw_auto_init_in_ref_error(prop);
3463
10
      return 0;
3464
10
    }
3465
45
  } ZEND_REF_FOREACH_TYPE_SOURCES_END();
3466
5
  return 1;
3467
15
}
3468
3469
static zend_never_inline bool zend_handle_fetch_obj_flags(
3470
    zval *result, zval *ptr, zend_object *obj, zend_property_info *prop_info, uint32_t flags)
3471
1.44k
{
3472
1.44k
  switch (flags) {
3473
115
    case ZEND_FETCH_DIM_WRITE:
3474
115
      if (promotes_to_array(ptr)) {
3475
46
        if (!prop_info) {
3476
0
          break;
3477
0
        }
3478
46
        if (!check_type_array_assignable(prop_info->type)) {
3479
15
          zend_throw_auto_init_in_prop_error(prop_info);
3480
15
          if (result) ZVAL_ERROR(result);
3481
15
          return 0;
3482
15
        }
3483
46
      }
3484
100
      break;
3485
1.32k
    case ZEND_FETCH_REF:
3486
1.32k
      if (Z_TYPE_P(ptr) != IS_REFERENCE) {
3487
836
        if (!prop_info) {
3488
0
          break;
3489
0
        }
3490
836
        if (Z_TYPE_P(ptr) == IS_UNDEF) {
3491
67
          if (!ZEND_TYPE_ALLOW_NULL(prop_info->type)) {
3492
23
            zend_throw_access_uninit_prop_by_ref_error(prop_info);
3493
23
            if (result) ZVAL_ERROR(result);
3494
23
            return 0;
3495
23
          }
3496
44
          ZVAL_NULL(ptr);
3497
44
        }
3498
3499
813
        ZVAL_NEW_REF(ptr, ptr);
3500
813
        ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(ptr), prop_info);
3501
813
      }
3502
1.30k
      break;
3503
1.44k
    EMPTY_SWITCH_DEFAULT_CASE()
3504
1.44k
  }
3505
1.40k
  return 1;
3506
1.44k
}
3507
3508
static zend_always_inline void zend_fetch_property_address(zval *result, zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, void **cache_slot, int type, uint32_t flags, zend_property_info **prop_info_p OPLINE_DC EXECUTE_DATA_DC)
3509
9.21k
{
3510
9.21k
  zval *ptr;
3511
9.21k
  zend_object *zobj;
3512
9.21k
  zend_string *name, *tmp_name;
3513
9.21k
  void *_cache_slot[3] = {0};
3514
9.21k
  if (prop_op_type != IS_CONST) {
3515
1.16k
    cache_slot = _cache_slot;
3516
8.05k
  } else {
3517
8.05k
    ZEND_ASSERT(cache_slot);
3518
8.05k
  }
3519
3520
9.21k
  if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
3521
340
    do {
3522
340
      if (Z_ISREF_P(container) && Z_TYPE_P(Z_REFVAL_P(container)) == IS_OBJECT) {
3523
113
        container = Z_REFVAL_P(container);
3524
113
        break;
3525
113
      }
3526
3527
227
      if (container_op_type == IS_CV
3528
122
       && type != BP_VAR_W
3529
30
       && UNEXPECTED(Z_TYPE_P(container) == IS_UNDEF)) {
3530
30
        ZVAL_UNDEFINED_OP1();
3531
30
      }
3532
3533
      /* this should modify object only if it's empty */
3534
227
      if (type == BP_VAR_UNSET) {
3535
47
        ZVAL_NULL(result);
3536
47
        return;
3537
47
      }
3538
3539
180
      zend_throw_non_object_error(container, prop_ptr OPLINE_CC EXECUTE_DATA_CC);
3540
180
      ZVAL_ERROR(result);
3541
180
      return;
3542
227
    } while (0);
3543
340
  }
3544
3545
8.99k
  zobj = Z_OBJ_P(container);
3546
8.99k
  if (prop_op_type == IS_CONST &&
3547
7.86k
      EXPECTED(zobj->ce == CACHED_PTR_EX(cache_slot))) {
3548
4.48k
    uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1);
3549
4.48k
    if (prop_info_p) {
3550
68
      *prop_info_p = CACHED_PTR_EX(cache_slot + 2);
3551
68
    }
3552
3553
4.48k
    if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
3554
3.35k
      ptr = OBJ_PROP(zobj, prop_offset);
3555
3.35k
      if (EXPECTED(Z_TYPE_P(ptr) != IS_UNDEF)) {
3556
3.15k
        ZVAL_INDIRECT(result, ptr);
3557
3.15k
        zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);
3558
3.15k
        if (prop_info) {
3559
589
          if (UNEXPECTED(prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))
3560
61
           && ((prop_info->flags & ZEND_ACC_READONLY) || !zend_asymmetric_property_has_set_access(prop_info))) {
3561
            /* For objects, W/RW/UNSET fetch modes might not actually modify object.
3562
             * Similar as with magic __get() allow them, but return the value as a copy
3563
             * to make sure no actual modification is possible. */
3564
61
            ZEND_ASSERT(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET);
3565
61
            if (Z_TYPE_P(ptr) == IS_OBJECT) {
3566
26
              ZVAL_COPY(result, ptr);
3567
35
            } else {
3568
35
              if (prop_info->flags & ZEND_ACC_READONLY) {
3569
25
                zend_readonly_property_indirect_modification_error(prop_info);
3570
25
              } else {
3571
10
                zend_asymmetric_visibility_property_modification_error(prop_info, "indirectly modify");
3572
10
              }
3573
35
              ZVAL_ERROR(result);
3574
35
            }
3575
61
            return;
3576
61
          }
3577
528
          flags &= ZEND_FETCH_OBJ_FLAGS;
3578
528
          if (flags) {
3579
281
            zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags);
3580
281
          }
3581
528
        }
3582
3.09k
        return;
3583
3.15k
      }
3584
3.35k
    } else if (UNEXPECTED(IS_HOOKED_PROPERTY_OFFSET(prop_offset))) {
3585
      /* Fall through to read_property for hooks. */
3586
1.09k
    } else if (EXPECTED(zobj->properties != NULL)) {
3587
427
      ZEND_ASSERT(IS_DYNAMIC_PROPERTY_OFFSET(prop_offset));
3588
427
      if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
3589
4
        if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
3590
4
          GC_DELREF(zobj->properties);
3591
4
        }
3592
4
        zobj->properties = zend_array_dup(zobj->properties);
3593
4
      }
3594
427
      ptr = zend_hash_find_known_hash(zobj->properties, Z_STR_P(prop_ptr));
3595
427
      if (EXPECTED(ptr)) {
3596
406
        ZVAL_INDIRECT(result, ptr);
3597
406
        return;
3598
406
      }
3599
427
    }
3600
4.51k
  } else if (prop_op_type == IS_CONST) {
3601
    /* CE mismatch, make cache slot consistent */
3602
3.38k
    cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
3603
3.38k
  }
3604
3605
  /* Pointer on property callback is required */
3606
5.43k
  ZEND_ASSERT(zobj->handlers->get_property_ptr_ptr != NULL);
3607
3608
5.43k
  if (prop_op_type == IS_CONST) {
3609
4.30k
    name = Z_STR_P(prop_ptr);
3610
4.30k
  } else {
3611
1.12k
    name = zval_get_tmp_string(prop_ptr, &tmp_name);
3612
1.12k
  }
3613
5.43k
  ptr = zobj->handlers->get_property_ptr_ptr(zobj, name, type, cache_slot);
3614
5.43k
  if (NULL == ptr) {
3615
1.03k
    ptr = zobj->handlers->read_property(zobj, name, type, cache_slot, result);
3616
1.03k
    if (ptr == result) {
3617
744
      if (UNEXPECTED(Z_ISREF_P(ptr) && Z_REFCOUNT_P(ptr) == 1)) {
3618
19
        ZVAL_UNREF(ptr);
3619
19
      }
3620
744
      goto end;
3621
744
    }
3622
289
    if (UNEXPECTED(EG(exception))) {
3623
218
      ZVAL_ERROR(result);
3624
218
      goto end;
3625
218
    }
3626
4.39k
  } else if (UNEXPECTED(Z_ISERROR_P(ptr))) {
3627
28
    ZVAL_ERROR(result);
3628
28
    goto end;
3629
4.37k
  } else if (type == BP_VAR_UNSET && UNEXPECTED(Z_TYPE_P(ptr) == IS_UNDEF)) {
3630
19
    ZVAL_NULL(result);
3631
19
    goto end;
3632
19
  }
3633
3634
4.42k
  ZVAL_INDIRECT(result, ptr);
3635
4.42k
  flags &= ZEND_FETCH_OBJ_FLAGS;
3636
4.42k
  if (flags) {
3637
3.13k
    zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);
3638
3.13k
    if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
3639
1.04k
      if (UNEXPECTED(!zend_handle_fetch_obj_flags(result, ptr, NULL, prop_info, flags))) {
3640
30
        goto end;
3641
30
      }
3642
1.04k
    }
3643
3.13k
  }
3644
3645
5.43k
end:
3646
5.43k
  if (prop_info_p) {
3647
986
    *prop_info_p = CACHED_PTR_EX(cache_slot + 2);
3648
986
  }
3649
5.43k
  if (prop_op_type != IS_CONST) {
3650
1.12k
    zend_tmp_string_release(tmp_name);
3651
1.12k
  }
3652
5.43k
}
3653
3654
static zend_always_inline void zend_assign_to_property_reference(zval *container, uint32_t container_op_type, zval *prop_ptr, uint32_t prop_op_type, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
3655
1.06k
{
3656
1.06k
  zval variable, *variable_ptr = &variable;
3657
1.06k
  void **cache_addr = (prop_op_type == IS_CONST) ? CACHE_ADDR(opline->extended_value & ~ZEND_RETURNS_FUNCTION) : NULL;
3658
1.06k
  zend_refcounted *garbage = NULL;
3659
1.06k
  zend_property_info *prop_info = NULL;
3660
3661
1.06k
  zend_fetch_property_address(variable_ptr, container, container_op_type, prop_ptr, prop_op_type,
3662
1.06k
    cache_addr, BP_VAR_W, 0, &prop_info OPLINE_CC EXECUTE_DATA_CC);
3663
3664
1.06k
  if (EXPECTED(Z_TYPE_P(variable_ptr) == IS_INDIRECT)) {
3665
957
    variable_ptr = Z_INDIRECT_P(variable_ptr);
3666
957
    if (/*OP_DATA_TYPE == IS_VAR &&*/
3667
957
           (opline->extended_value & ZEND_RETURNS_FUNCTION) &&
3668
6
           UNEXPECTED(!Z_ISREF_P(value_ptr))) {
3669
3670
6
      variable_ptr = zend_wrong_assign_to_variable_reference(
3671
6
        variable_ptr, value_ptr, &garbage OPLINE_CC EXECUTE_DATA_CC);
3672
951
    } else if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
3673
527
      variable_ptr = zend_assign_to_typed_property_reference(prop_info, variable_ptr, value_ptr, &garbage EXECUTE_DATA_CC);
3674
527
    } else {
3675
424
      zend_assign_to_variable_reference(variable_ptr, value_ptr, &garbage);
3676
424
    }
3677
957
  } else if (Z_ISERROR_P(variable_ptr)) {
3678
57
    variable_ptr = &EG(uninitialized_zval);
3679
57
  } else {
3680
52
    zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
3681
52
    zval_ptr_dtor(&variable);
3682
52
    variable_ptr = &EG(uninitialized_zval);
3683
52
  }
3684
3685
1.06k
  if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
3686
135
    ZVAL_COPY(EX_VAR(opline->result.var), variable_ptr);
3687
135
  }
3688
1.06k
  if (garbage) {
3689
383
    GC_DTOR(garbage);
3690
383
  }
3691
1.06k
}
3692
3693
static zend_never_inline void zend_assign_to_property_reference_this_const(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
3694
148
{
3695
148
  zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_CONST, value_ptr
3696
148
    OPLINE_CC EXECUTE_DATA_CC);
3697
148
}
3698
3699
static zend_never_inline void zend_assign_to_property_reference_var_const(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
3700
434
{
3701
434
  zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_CONST, value_ptr
3702
434
    OPLINE_CC EXECUTE_DATA_CC);
3703
434
}
3704
3705
static zend_never_inline void zend_assign_to_property_reference_this_var(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
3706
15
{
3707
15
  zend_assign_to_property_reference(container, IS_UNUSED, prop_ptr, IS_VAR, value_ptr
3708
15
    OPLINE_CC EXECUTE_DATA_CC);
3709
15
}
3710
3711
static zend_never_inline void zend_assign_to_property_reference_var_var(zval *container, zval *prop_ptr, zval *value_ptr OPLINE_DC EXECUTE_DATA_DC)
3712
469
{
3713
469
  zend_assign_to_property_reference(container, IS_VAR, prop_ptr, IS_VAR, value_ptr
3714
469
    OPLINE_CC EXECUTE_DATA_CC);
3715
469
}
3716
3717
3.62k
static zend_never_inline zval* zend_fetch_static_property_address_ex(zend_property_info **prop_info, uint32_t cache_slot, int fetch_type OPLINE_DC EXECUTE_DATA_DC) {
3718
3.62k
  zval *result;
3719
3.62k
  zend_string *name;
3720
3.62k
  zend_class_entry *ce;
3721
3.62k
  zend_property_info *property_info;
3722
3723
3.62k
  uint8_t op1_type = opline->op1_type, op2_type = opline->op2_type;
3724
3725
3.62k
  if (EXPECTED(op2_type == IS_CONST)) {
3726
2.14k
    zval *class_name = RT_CONSTANT(opline, opline->op2);
3727
3728
2.14k
    ZEND_ASSERT(op1_type != IS_CONST || CACHED_PTR(cache_slot) == NULL);
3729
3730
2.14k
    if (EXPECTED((ce = CACHED_PTR(cache_slot)) == NULL)) {
3731
2.02k
      ce = zend_fetch_class_by_name(Z_STR_P(class_name), Z_STR_P(class_name + 1), ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION);
3732
2.02k
      if (UNEXPECTED(ce == NULL)) {
3733
97
        FREE_OP(op1_type, opline->op1.var);
3734
97
        return NULL;
3735
97
      }
3736
1.93k
      if (UNEXPECTED(op1_type != IS_CONST)) {
3737
40
        CACHE_PTR(cache_slot, ce);
3738
40
      }
3739
1.93k
    }
3740
2.14k
  } else {
3741
1.48k
    if (EXPECTED(op2_type == IS_UNUSED)) {
3742
1.37k
      ce = zend_fetch_class(NULL, opline->op2.num);
3743
1.37k
      if (UNEXPECTED(ce == NULL)) {
3744
24
        FREE_OP(op1_type, opline->op1.var);
3745
24
        return NULL;
3746
24
      }
3747
1.37k
    } else {
3748
108
      ce = Z_CE_P(EX_VAR(opline->op2.var));
3749
108
    }
3750
1.45k
    if (EXPECTED(op1_type == IS_CONST) && EXPECTED(CACHED_PTR(cache_slot) == ce)) {
3751
45
      result = CACHED_PTR(cache_slot + sizeof(void *));
3752
45
      *prop_info = CACHED_PTR(cache_slot + sizeof(void *) * 2);
3753
45
      return result;
3754
45
    }
3755
1.45k
  }
3756
3757
3.46k
  if (EXPECTED(op1_type == IS_CONST)) {
3758
3.29k
    name = Z_STR_P(RT_CONSTANT(opline, opline->op1));
3759
3.29k
    result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info);
3760
3.29k
  } else {
3761
170
    zend_string *tmp_name;
3762
170
    zval *varname = get_zval_ptr_undef(opline->op1_type, opline->op1, BP_VAR_R);
3763
170
    if (EXPECTED(Z_TYPE_P(varname) == IS_STRING)) {
3764
143
      name = Z_STR_P(varname);
3765
143
      tmp_name = NULL;
3766
143
    } else {
3767
27
      if (op1_type == IS_CV && UNEXPECTED(Z_TYPE_P(varname) == IS_UNDEF)) {
3768
10
        zval_undefined_cv(opline->op1.var EXECUTE_DATA_CC);
3769
10
      }
3770
27
      name = zval_get_tmp_string(varname, &tmp_name);
3771
27
    }
3772
170
    result = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info);
3773
3774
170
    zend_tmp_string_release(tmp_name);
3775
3776
170
    FREE_OP(op1_type, opline->op1.var);
3777
170
  }
3778
3779
3.46k
  if (UNEXPECTED(result == NULL)) {
3780
412
    return NULL;
3781
412
  }
3782
3783
3.04k
  if (UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF)
3784
321
   && (fetch_type == BP_VAR_IS || fetch_type == BP_VAR_UNSET)) {
3785
26
    return NULL;
3786
26
   }
3787
3788
3.02k
  *prop_info = property_info;
3789
3790
3.02k
  if (EXPECTED(op1_type == IS_CONST)
3791
2.89k
      && EXPECTED(!(property_info->ce->ce_flags & ZEND_ACC_TRAIT))) {
3792
2.83k
    CACHE_POLYMORPHIC_PTR(cache_slot, ce, result);
3793
2.83k
    CACHE_PTR(cache_slot + sizeof(void *) * 2, property_info);
3794
2.83k
  }
3795
3796
3.02k
  return result;
3797
3.04k
}
3798
3799
3800
8.27k
static zend_always_inline zval* zend_fetch_static_property_address(zend_property_info **prop_info, uint32_t cache_slot, int fetch_type, int flags OPLINE_DC EXECUTE_DATA_DC) {
3801
8.27k
  zval *result;
3802
8.27k
  zend_property_info *property_info;
3803
3804
8.27k
  if (opline->op1_type == IS_CONST
3805
8.08k
   && (opline->op2_type == IS_CONST
3806
4.61k
    || (opline->op2_type == IS_UNUSED
3807
4.50k
     && ((opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
3808
262
      || (opline->op2.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT)))
3809
7.73k
   && EXPECTED(CACHED_PTR(cache_slot + sizeof(void *)) != NULL)) {
3810
4.64k
    result = CACHED_PTR(cache_slot + sizeof(void *));
3811
4.64k
    property_info = CACHED_PTR(cache_slot + sizeof(void *) * 2);
3812
3813
4.64k
    if ((fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW)
3814
2.72k
        && UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF)
3815
10
        && ZEND_TYPE_IS_SET(property_info->type)) {
3816
10
      zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization",
3817
10
        ZSTR_VAL(property_info->ce->name),
3818
10
        zend_get_unmangled_property_name(property_info->name));
3819
10
      return NULL;
3820
10
    }
3821
4.64k
  } else {
3822
3.62k
    result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC);
3823
3.62k
    if (UNEXPECTED(!result)) {
3824
559
      return NULL;
3825
559
    }
3826
3.62k
  }
3827
3828
7.70k
  flags &= ZEND_FETCH_OBJ_FLAGS;
3829
7.70k
  if (flags && ZEND_TYPE_IS_SET(property_info->type)) {
3830
117
    zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags);
3831
117
  }
3832
3833
7.70k
  if (prop_info) {
3834
7.56k
    *prop_info = property_info;
3835
7.56k
  }
3836
3837
7.70k
  return result;
3838
8.27k
}
3839
3840
0
ZEND_API zval* ZEND_FASTCALL zend_fetch_static_property(zend_execute_data *ex, int fetch_type) {
3841
0
  zval *result;
3842
0
  zend_property_info *property_info;
3843
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3844
  zend_execute_data *orig_execute_data = execute_data;
3845
#else
3846
0
  zend_execute_data *execute_data;
3847
0
#endif
3848
0
  execute_data = ex;
3849
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3850
  const zend_op *orig_opline = opline;
3851
#else
3852
0
  const zend_op *opline;
3853
0
#endif
3854
0
  opline = execute_data->opline;
3855
3856
0
  uint32_t cache_slot = opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS;
3857
0
  uint32_t flags = 0;
3858
3859
0
  if (fetch_type == BP_VAR_W) {
3860
0
    flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS;
3861
0
  }
3862
0
  result = zend_fetch_static_property_address_ex(&property_info, cache_slot, fetch_type OPLINE_CC EXECUTE_DATA_CC);
3863
0
  if (EXPECTED(result)) {
3864
0
    if (flags && ZEND_TYPE_IS_SET(property_info->type)) {
3865
0
      zend_handle_fetch_obj_flags(NULL, result, NULL, property_info, flags);
3866
0
    }
3867
0
  } else {
3868
0
    result = &EG(uninitialized_zval);
3869
0
  }
3870
3871
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3872
  EX(opline) = opline;
3873
  opline = orig_opline;
3874
#endif
3875
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
3876
  execute_data = orig_execute_data;
3877
#endif
3878
3879
0
  return result;
3880
0
}
3881
3882
62
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) {
3883
62
  zend_string *type1_str = zend_type_to_string(prop1->type);
3884
62
  zend_string *type2_str = zend_type_to_string(prop2->type);
3885
62
  zend_type_error("Reference with value of type %s held by property %s::$%s of type %s is not compatible with property %s::$%s of type %s",
3886
62
    zend_zval_type_name(zv),
3887
62
    ZSTR_VAL(prop1->ce->name),
3888
62
    zend_get_unmangled_property_name(prop1->name),
3889
62
    ZSTR_VAL(type1_str),
3890
62
    ZSTR_VAL(prop2->ce->name),
3891
62
    zend_get_unmangled_property_name(prop2->name),
3892
62
    ZSTR_VAL(type2_str)
3893
62
  );
3894
62
  zend_string_release(type1_str);
3895
62
  zend_string_release(type2_str);
3896
62
}
3897
3898
400
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv) {
3899
400
  zend_string *type_str = zend_type_to_string(prop->type);
3900
400
  zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s",
3901
400
    zend_zval_value_name(zv),
3902
400
    ZSTR_VAL(prop->ce->name),
3903
400
    zend_get_unmangled_property_name(prop->name),
3904
400
    ZSTR_VAL(type_str)
3905
400
  );
3906
400
  zend_string_release(type_str);
3907
400
}
3908
3909
37
ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) {
3910
37
  zend_string *type1_str = zend_type_to_string(prop1->type);
3911
37
  zend_string *type2_str = zend_type_to_string(prop2->type);
3912
37
  zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s and property %s::$%s of type %s, as this would result in an inconsistent type conversion",
3913
37
    zend_zval_value_name(zv),
3914
37
    ZSTR_VAL(prop1->ce->name),
3915
37
    zend_get_unmangled_property_name(prop1->name),
3916
37
    ZSTR_VAL(type1_str),
3917
37
    ZSTR_VAL(prop2->ce->name),
3918
37
    zend_get_unmangled_property_name(prop2->name),
3919
37
    ZSTR_VAL(type2_str)
3920
37
  );
3921
37
  zend_string_release(type1_str);
3922
37
  zend_string_release(type2_str);
3923
37
}
3924
3925
/* 1: valid, 0: invalid, -1: may be valid after type coercion */
3926
static zend_always_inline int i_zend_verify_type_assignable_zval(
3927
30.5k
    const zend_property_info *info, const zval *zv, bool strict) {
3928
30.5k
  zend_type type = info->type;
3929
30.5k
  uint32_t type_mask;
3930
30.5k
  uint8_t zv_type = Z_TYPE_P(zv);
3931
3932
30.5k
  if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(type, zv_type))) {
3933
17.1k
    return 1;
3934
17.1k
  }
3935
3936
13.4k
  if (ZEND_TYPE_IS_COMPLEX(type) && zv_type == IS_OBJECT
3937
12.9k
      && zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(zv))) {
3938
12.8k
    return 1;
3939
12.8k
  }
3940
3941
644
  type_mask = ZEND_TYPE_FULL_MASK(type);
3942
644
  ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_STATIC)));
3943
3944
  /* SSTH Exception: IS_LONG may be accepted as IS_DOUBLE (converted) */
3945
644
  if (strict) {
3946
27
    if ((type_mask & MAY_BE_DOUBLE) && zv_type == IS_LONG) {
3947
0
      return -1;
3948
0
    }
3949
27
    return 0;
3950
27
  }
3951
3952
  /* NULL may be accepted only by nullable hints (this is already checked) */
3953
617
  if (zv_type == IS_NULL) {
3954
92
    return 0;
3955
92
  }
3956
3957
  /* Does not contain any type to which a coercion is possible */
3958
525
  if (!(type_mask & (MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING))
3959
204
      && (type_mask & MAY_BE_BOOL) != MAY_BE_BOOL) {
3960
204
    return 0;
3961
204
  }
3962
3963
  /* Coercion may be necessary, check separately */
3964
321
  return -1;
3965
525
}
3966
3967
ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict)
3968
1.54k
{
3969
1.54k
  const zend_property_info *prop;
3970
3971
  /* The value must satisfy each property type, and coerce to the same value for each property
3972
   * type. Remember the first coerced type and value we've seen for this purpose. */
3973
1.54k
  const zend_property_info *first_prop = NULL;
3974
1.54k
  zval coerced_value;
3975
1.54k
  ZVAL_UNDEF(&coerced_value);
3976
3977
1.54k
  ZEND_ASSERT(Z_TYPE_P(zv) != IS_REFERENCE);
3978
4.93k
  ZEND_REF_FOREACH_TYPE_SOURCES(ref, prop) {
3979
4.93k
    int result = i_zend_verify_type_assignable_zval(prop, zv, strict);
3980
4.93k
    if (result == 0) {
3981
400
type_error:
3982
400
      zend_throw_ref_type_error_zval(prop, zv);
3983
400
      zval_ptr_dtor(&coerced_value);
3984
400
      return 0;
3985
283
    }
3986
3987
1.56k
    if (result < 0) {
3988
257
      if (!first_prop) {
3989
234
        first_prop = prop;
3990
234
        ZVAL_COPY(&coerced_value, zv);
3991
234
        if (!zend_verify_weak_scalar_type_hint(
3992
234
            ZEND_TYPE_FULL_MASK(prop->type), &coerced_value)) {
3993
117
          goto type_error;
3994
117
        }
3995
234
      } else if (Z_ISUNDEF(coerced_value)) {
3996
        /* A previous property did not require coercion, but this one does,
3997
         * so they are incompatible. */
3998
17
        goto conflicting_coercion_error;
3999
17
      } else {
4000
6
        zval tmp;
4001
6
        ZVAL_COPY(&tmp, zv);
4002
6
        if (!zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop->type), &tmp)) {
4003
0
          zval_ptr_dtor(&tmp);
4004
0
          goto type_error;
4005
0
        }
4006
6
        if (!zend_is_identical(&coerced_value, &tmp)) {
4007
0
          zval_ptr_dtor(&tmp);
4008
0
          goto conflicting_coercion_error;
4009
0
        }
4010
6
        zval_ptr_dtor(&tmp);
4011
6
      }
4012
1.30k
    } else {
4013
1.30k
      if (!first_prop) {
4014
1.10k
        first_prop = prop;
4015
1.10k
      } else if (!Z_ISUNDEF(coerced_value)) {
4016
        /* A previous property required coercion, but this one doesn't,
4017
         * so they are incompatible. */
4018
37
conflicting_coercion_error:
4019
37
        zend_throw_conflicting_coercion_error(first_prop, prop, zv);
4020
37
        zval_ptr_dtor(&coerced_value);
4021
37
        return 0;
4022
20
      }
4023
1.30k
    }
4024
1.56k
  } ZEND_REF_FOREACH_TYPE_SOURCES_END();
4025
4026
1.10k
  if (!Z_ISUNDEF(coerced_value)) {
4027
97
    zval_ptr_dtor(zv);
4028
97
    ZVAL_COPY_VALUE(zv, &coerced_value);
4029
97
  }
4030
4031
1.10k
  return 1;
4032
1.54k
}
4033
4034
836
static zend_always_inline void i_zval_ptr_dtor_noref(zval *zval_ptr) {
4035
836
  if (Z_REFCOUNTED_P(zval_ptr)) {
4036
338
    zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
4037
338
    ZEND_ASSERT(Z_TYPE_P(zval_ptr) != IS_REFERENCE);
4038
338
    GC_DTOR_NO_REF(ref);
4039
338
  }
4040
836
}
4041
4042
ZEND_API zval* zend_assign_to_typed_ref_ex(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict, zend_refcounted **garbage_ptr)
4043
1.25k
{
4044
1.25k
  bool ret;
4045
1.25k
  zval value;
4046
1.25k
  zend_refcounted *ref = NULL;
4047
4048
1.25k
  if (Z_ISREF_P(orig_value)) {
4049
0
    ref = Z_COUNTED_P(orig_value);
4050
0
    orig_value = Z_REFVAL_P(orig_value);
4051
0
  }
4052
4053
1.25k
  ZVAL_COPY(&value, orig_value);
4054
1.25k
  ret = zend_verify_ref_assignable_zval(Z_REF_P(variable_ptr), &value, strict);
4055
1.25k
  variable_ptr = Z_REFVAL_P(variable_ptr);
4056
1.25k
  if (EXPECTED(ret)) {
4057
859
    if (Z_REFCOUNTED_P(variable_ptr)) {
4058
279
      *garbage_ptr = Z_COUNTED_P(variable_ptr);
4059
279
    }
4060
859
    ZVAL_COPY_VALUE(variable_ptr, &value);
4061
859
  } else {
4062
399
    zval_ptr_dtor_nogc(&value);
4063
399
  }
4064
1.25k
  if (value_type & (IS_VAR|IS_TMP_VAR)) {
4065
836
    if (UNEXPECTED(ref)) {
4066
0
      if (UNEXPECTED(GC_DELREF(ref) == 0)) {
4067
0
        zval_ptr_dtor(orig_value);
4068
0
        efree_size(ref, sizeof(zend_reference));
4069
0
      }
4070
836
    } else {
4071
836
      i_zval_ptr_dtor_noref(orig_value);
4072
836
    }
4073
836
  }
4074
1.25k
  return variable_ptr;
4075
1.25k
}
4076
4077
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, uint8_t value_type, bool strict)
4078
342
{
4079
342
  zend_refcounted *garbage = NULL;
4080
342
  zval *result = zend_assign_to_typed_ref_ex(variable_ptr, orig_value, value_type, strict, &garbage);
4081
342
  if (garbage) {
4082
12
    GC_DTOR_NO_REF(garbage);
4083
12
  }
4084
342
  return result;
4085
342
}
4086
4087
123k
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref_ex(const zend_property_info *prop_info, zval *orig_val, bool strict, zend_verify_prop_assignable_by_ref_context context) {
4088
123k
  zval *val = orig_val;
4089
123k
  if (Z_ISREF_P(val) && ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(val))) {
4090
28.7k
    int result;
4091
4092
28.7k
    val = Z_REFVAL_P(val);
4093
28.7k
    result = i_zend_verify_type_assignable_zval(prop_info, val, strict);
4094
28.7k
    if (result > 0) {
4095
28.6k
      return 1;
4096
28.6k
    }
4097
4098
104
    if (result < 0) {
4099
      /* This is definitely an error, but we still need to determined why: Either because
4100
       * the value is simply illegal for the type, or because or a conflicting coercion. */
4101
64
      zval tmp;
4102
64
      ZVAL_COPY(&tmp, val);
4103
64
      if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop_info->type), &tmp)) {
4104
62
        const zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val));
4105
62
        zend_throw_ref_type_error_type(ref_prop, prop_info, val);
4106
62
        zval_ptr_dtor(&tmp);
4107
62
        return 0;
4108
62
      }
4109
2
      zval_ptr_dtor(&tmp);
4110
2
    }
4111
94.3k
  } else {
4112
94.3k
    ZVAL_DEREF(val);
4113
94.3k
    if (i_zend_check_property_type(prop_info, val, strict)) {
4114
94.3k
      return 1;
4115
94.3k
    }
4116
94.3k
  }
4117
4118
127
  if (EXPECTED(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT)) {
4119
111
    zend_verify_property_type_error(prop_info, val);
4120
111
  } else {
4121
16
    ZEND_ASSERT(context == ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_MAGIC_GET);
4122
16
    zend_magic_get_property_type_inconsistency_error(prop_info, val);
4123
16
  }
4124
4125
127
  return 0;
4126
127
}
4127
4128
123k
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict) {
4129
123k
  return zend_verify_prop_assignable_by_ref_ex(prop_info, orig_val, strict, ZEND_VERIFY_PROP_ASSIGNABLE_BY_REF_CONTEXT_ASSIGNMENT);
4130
123k
}
4131
4132
ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop)
4133
30.8k
{
4134
30.8k
  zend_property_info_list *list;
4135
30.8k
  if (source_list->ptr == NULL) {
4136
2.17k
    source_list->ptr = prop;
4137
2.17k
    return;
4138
2.17k
  }
4139
4140
28.6k
  list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list);
4141
28.6k
  if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) {
4142
505
    list = emalloc(sizeof(zend_property_info_list) + (4 - 1) * sizeof(zend_property_info *));
4143
505
    list->ptr[0] = source_list->ptr;
4144
505
    list->num_allocated = 4;
4145
505
    list->num = 1;
4146
28.1k
  } else if (list->num_allocated == list->num) {
4147
568
    list->num_allocated = list->num * 2;
4148
568
    list = erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *));
4149
568
  }
4150
4151
28.6k
  list->ptr[list->num++] = prop;
4152
28.6k
  source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(list);
4153
28.6k
}
4154
4155
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop)
4156
30.8k
{
4157
30.8k
  zend_property_info_list *list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list);
4158
30.8k
  zend_property_info **ptr, **end;
4159
4160
30.8k
  ZEND_ASSERT(prop);
4161
30.8k
  if (!ZEND_PROPERTY_INFO_SOURCE_IS_LIST(source_list->list)) {
4162
1.66k
    ZEND_ASSERT(source_list->ptr == prop);
4163
1.66k
    source_list->ptr = NULL;
4164
1.66k
    return;
4165
1.66k
  }
4166
4167
29.1k
  if (list->num == 1) {
4168
505
    ZEND_ASSERT(*list->ptr == prop);
4169
505
    efree(list);
4170
505
    source_list->ptr = NULL;
4171
505
    return;
4172
505
  }
4173
4174
  /* Checking against end here to get a more graceful failure mode if we missed adding a type
4175
   * source at some point. */
4176
28.6k
  ptr = list->ptr;
4177
28.6k
  end = ptr + list->num;
4178
29.1k
  while (ptr < end && *ptr != prop) {
4179
504
    ptr++;
4180
504
  }
4181
28.6k
  ZEND_ASSERT(*ptr == prop);
4182
4183
  /* Copy the last list element into the deleted slot. */
4184
28.6k
  *ptr = list->ptr[--list->num];
4185
4186
28.6k
  if (list->num >= 4 && list->num * 4 == list->num_allocated) {
4187
408
    list->num_allocated = list->num * 2;
4188
408
    source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(erealloc(list, sizeof(zend_property_info_list) + (list->num_allocated - 1) * sizeof(zend_property_info *)));
4189
408
  }
4190
28.6k
}
4191
4192
static zend_never_inline void zend_fetch_this_var(int type OPLINE_DC EXECUTE_DATA_DC)
4193
104
{
4194
104
  zval *result = EX_VAR(opline->result.var);
4195
4196
104
  switch (type) {
4197
100
    case BP_VAR_R:
4198
100
      if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
4199
96
        ZVAL_OBJ(result, Z_OBJ(EX(This)));
4200
96
        Z_ADDREF_P(result);
4201
96
      } else {
4202
4
        ZVAL_NULL(result);
4203
4
        zend_error_unchecked(E_WARNING, "Undefined variable $this");
4204
4
      }
4205
100
      break;
4206
0
    case BP_VAR_IS:
4207
0
      if (EXPECTED(Z_TYPE(EX(This)) == IS_OBJECT)) {
4208
0
        ZVAL_OBJ(result, Z_OBJ(EX(This)));
4209
0
        Z_ADDREF_P(result);
4210
0
      } else {
4211
0
        ZVAL_NULL(result);
4212
0
      }
4213
0
      break;
4214
0
    case BP_VAR_RW:
4215
4
    case BP_VAR_W:
4216
4
      ZVAL_UNDEF(result);
4217
4
      zend_throw_error(NULL, "Cannot re-assign $this");
4218
4
      break;
4219
0
    case BP_VAR_UNSET:
4220
0
      ZVAL_UNDEF(result);
4221
0
      zend_throw_error(NULL, "Cannot unset $this");
4222
0
      break;
4223
104
    EMPTY_SWITCH_DEFAULT_CASE()
4224
104
  }
4225
104
}
4226
4227
#if ZEND_INTENSIVE_DEBUGGING
4228
4229
#define CHECK_SYMBOL_TABLES()                         \
4230
  zend_hash_apply(&EG(symbol_table), zend_check_symbol);      \
4231
  if (&EG(symbol_table)!=EX(symbol_table)) {              \
4232
    zend_hash_apply(EX(symbol_table), zend_check_symbol); \
4233
  }
4234
4235
static void zend_check_symbol(zval *pz)
4236
{
4237
  if (Z_TYPE_P(pz) == IS_INDIRECT) {
4238
    pz = Z_INDIRECT_P(pz);
4239
  }
4240
  if (Z_TYPE_P(pz) > 10) {
4241
    fprintf(stderr, "Warning!  %x has invalid type!\n", *pz);
4242
/* See http://support.microsoft.com/kb/190351 */
4243
#ifdef ZEND_WIN32
4244
    fflush(stderr);
4245
#endif
4246
  } else if (Z_TYPE_P(pz) == IS_ARRAY) {
4247
    zend_hash_apply(Z_ARRVAL_P(pz), zend_check_symbol);
4248
  } else if (Z_TYPE_P(pz) == IS_OBJECT) {
4249
    /* OBJ-TBI - doesn't support new object model! */
4250
    zend_hash_apply(Z_OBJPROP_P(pz), zend_check_symbol);
4251
  }
4252
}
4253
4254
4255
#else
4256
#define CHECK_SYMBOL_TABLES()
4257
#endif
4258
4259
ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value)
4260
960k
{
4261
960k
  execute_data->func->internal_function.handler(execute_data, return_value);
4262
960k
}
4263
4264
ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table) /* {{{ */
4265
3.68k
{
4266
  /* Clean before putting into the cache, since clean could call dtors,
4267
   * which could use the cached hash. Also do this before the check for
4268
   * available cache slots, as those may be used by a dtor as well. */
4269
3.68k
  zend_symtable_clean(symbol_table);
4270
3.68k
  if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) {
4271
235
    zend_array_destroy(symbol_table);
4272
3.44k
  } else {
4273
3.44k
    *(EG(symtable_cache_ptr)++) = symbol_table;
4274
3.44k
  }
4275
3.68k
}
4276
/* }}} */
4277
4278
static zend_always_inline void i_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */
4279
136k
{
4280
136k
  zval *cv = EX_VAR_NUM(0);
4281
136k
  int count = EX(func)->op_array.last_var;
4282
349k
  while (EXPECTED(count != 0)) {
4283
213k
    i_zval_ptr_dtor(cv);
4284
213k
    cv++;
4285
213k
    count--;
4286
213k
  }
4287
136k
}
4288
/* }}} */
4289
4290
ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data *execute_data) /* {{{ */
4291
5.43k
{
4292
5.43k
  i_free_compiled_variables(execute_data);
4293
5.43k
}
4294
/* }}} */
4295
4296
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data *call)
4297
0
{
4298
0
  zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
4299
0
  if (zend_atomic_bool_load_ex(&EG(timed_out))) {
4300
0
    zend_timeout();
4301
0
  } else if (zend_interrupt_function) {
4302
0
    zend_interrupt_function(call);
4303
0
  }
4304
0
}
4305
4306
1.10M
#define ZEND_VM_INTERRUPT_CHECK() do { \
4307
1.10M
    if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
4308
0
      ZEND_VM_INTERRUPT(); \
4309
0
    } \
4310
1.10M
  } while (0)
4311
4312
58.7k
#define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \
4313
58.7k
    if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
4314
0
      ZEND_VM_LOOP_INTERRUPT(); \
4315
0
    } \
4316
58.7k
  } while (0)
4317
4318
888k
#define ZEND_VM_FCALL_INTERRUPT_CHECK(call) do { \
4319
888k
    if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
4320
0
      zend_fcall_interrupt(call); \
4321
0
    } \
4322
888k
  } while (0)
4323
4324
/*
4325
 * Stack Frame Layout (the whole stack frame is allocated at once)
4326
 * ==================
4327
 *
4328
 *                             +========================================+
4329
 * EG(current_execute_data) -> | zend_execute_data                      |
4330
 *                             +----------------------------------------+
4331
 *     EX_VAR_NUM(0) --------> | VAR[0] = ARG[1]                        |
4332
 *                             | ...                                    |
4333
 *                             | VAR[op_array->num_args-1] = ARG[N]     |
4334
 *                             | ...                                    |
4335
 *                             | VAR[op_array->last_var-1]              |
4336
 *                             | VAR[op_array->last_var] = TMP[0]       |
4337
 *                             | ...                                    |
4338
 *                             | VAR[op_array->last_var+op_array->T-1]  |
4339
 *                             | ARG[N+1] (extra_args)                  |
4340
 *                             | ...                                    |
4341
 *                             +----------------------------------------+
4342
 */
4343
4344
/* zend_copy_extra_args is used when the actually passed number of arguments
4345
 * (EX_NUM_ARGS) is greater than what the function defined (op_array->num_args).
4346
 *
4347
 * The extra arguments will be copied into the call frame after all the compiled variables.
4348
 *
4349
 * If there are extra arguments copied, a flag "ZEND_CALL_FREE_EXTRA_ARGS" will be set
4350
 * on the zend_execute_data, and when the executor leaves the function, the
4351
 * args will be freed in zend_leave_helper.
4352
 */
4353
static zend_never_inline void zend_copy_extra_args(EXECUTE_DATA_D)
4354
8.50k
{
4355
8.50k
  const zend_op_array *op_array = &EX(func)->op_array;
4356
8.50k
  uint32_t first_extra_arg = op_array->num_args;
4357
8.50k
  uint32_t num_args = EX_NUM_ARGS();
4358
8.50k
  zval *src;
4359
8.50k
  size_t delta;
4360
8.50k
  uint32_t count;
4361
8.50k
  uint32_t type_flags = 0;
4362
4363
8.50k
  if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
4364
    /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
4365
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4366
    opline += first_extra_arg;
4367
#else
4368
8.39k
    EX(opline) += first_extra_arg;
4369
8.39k
#endif
4370
4371
8.39k
  }
4372
4373
  /* move extra args into separate array after all CV and TMP vars */
4374
8.50k
  src = EX_VAR_NUM(num_args - 1);
4375
8.50k
  delta = op_array->last_var + op_array->T - first_extra_arg;
4376
8.50k
  count = num_args - first_extra_arg;
4377
8.50k
  if (EXPECTED(delta != 0)) {
4378
6.13k
    delta *= sizeof(zval);
4379
450k
    do {
4380
450k
      type_flags |= Z_TYPE_INFO_P(src);
4381
450k
      ZVAL_COPY_VALUE((zval*)(((char*)src) + delta), src);
4382
450k
      ZVAL_UNDEF(src);
4383
450k
      src--;
4384
450k
    } while (--count);
4385
6.13k
    if (Z_TYPE_INFO_REFCOUNTED(type_flags)) {
4386
4.73k
      ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS);
4387
4.73k
    }
4388
6.13k
  } else {
4389
857k
    do {
4390
857k
      if (Z_REFCOUNTED_P(src)) {
4391
914
        ZEND_ADD_CALL_FLAG(execute_data, ZEND_CALL_FREE_EXTRA_ARGS);
4392
914
        break;
4393
914
      }
4394
856k
      src--;
4395
856k
    } while (--count);
4396
2.36k
  }
4397
8.50k
}
4398
4399
static zend_always_inline void zend_init_cvs(uint32_t first, uint32_t last EXECUTE_DATA_DC)
4400
167k
{
4401
167k
  if (EXPECTED(first < last)) {
4402
79.8k
    uint32_t count = last - first;
4403
79.8k
    zval *var = EX_VAR_NUM(first);
4404
4405
381k
    do {
4406
381k
      ZVAL_UNDEF(var);
4407
381k
      var++;
4408
381k
    } while (--count);
4409
79.8k
  }
4410
167k
}
4411
4412
static zend_always_inline void i_init_func_execute_data(zend_op_array *op_array, zval *return_value, bool may_be_trampoline EXECUTE_DATA_DC) /* {{{ */
4413
167k
{
4414
167k
  uint32_t first_extra_arg, num_args;
4415
167k
  ZEND_ASSERT(EX(func) == (zend_function*)op_array);
4416
4417
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4418
  opline = op_array->opcodes;
4419
#else
4420
167k
  EX(opline) = op_array->opcodes;
4421
167k
#endif
4422
167k
  EX(call) = NULL;
4423
167k
  EX(return_value) = return_value;
4424
4425
  /* Handle arguments */
4426
167k
  first_extra_arg = op_array->num_args;
4427
167k
  num_args = EX_NUM_ARGS();
4428
167k
  if (UNEXPECTED(num_args > first_extra_arg)) {
4429
9.61k
    if (!may_be_trampoline || EXPECTED(!(op_array->fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) {
4430
8.50k
      zend_copy_extra_args(EXECUTE_DATA_C);
4431
8.50k
    }
4432
157k
  } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) {
4433
    /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */
4434
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4435
    opline += num_args;
4436
#else
4437
144k
    EX(opline) += num_args;
4438
144k
#endif
4439
144k
  }
4440
4441
  /* Initialize CV variables (skip arguments) */
4442
167k
  zend_init_cvs(num_args, op_array->last_var EXECUTE_DATA_CC);
4443
4444
167k
  EX(run_time_cache) = RUN_TIME_CACHE(op_array);
4445
4446
167k
  EG(current_execute_data) = execute_data;
4447
167k
}
4448
/* }}} */
4449
4450
static zend_always_inline void init_func_run_time_cache_i(zend_op_array *op_array) /* {{{ */
4451
32.8k
{
4452
32.8k
  void **run_time_cache;
4453
4454
32.8k
  ZEND_ASSERT(RUN_TIME_CACHE(op_array) == NULL);
4455
32.8k
  run_time_cache = zend_arena_alloc(&CG(arena), op_array->cache_size);
4456
32.8k
  memset(run_time_cache, 0, op_array->cache_size);
4457
32.8k
  ZEND_MAP_PTR_SET(op_array->run_time_cache, run_time_cache);
4458
32.8k
}
4459
/* }}} */
4460
4461
static zend_never_inline void ZEND_FASTCALL init_func_run_time_cache(zend_op_array *op_array) /* {{{ */
4462
32.3k
{
4463
32.3k
  init_func_run_time_cache_i(op_array);
4464
32.3k
}
4465
/* }}} */
4466
4467
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function(zend_string *name) /* {{{ */
4468
5.93k
{
4469
5.93k
  zval *zv = zend_hash_find(EG(function_table), name);
4470
4471
5.93k
  if (EXPECTED(zv != NULL)) {
4472
3.66k
    zend_function *fbc = Z_FUNC_P(zv);
4473
4474
3.66k
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
4475
431
      init_func_run_time_cache_i(&fbc->op_array);
4476
431
    }
4477
3.66k
    return fbc;
4478
3.66k
  }
4479
2.27k
  return NULL;
4480
5.93k
} /* }}} */
4481
4482
ZEND_API zend_function * ZEND_FASTCALL zend_fetch_function_str(const char *name, size_t len) /* {{{ */
4483
17
{
4484
17
  zval *zv = zend_hash_str_find(EG(function_table), name, len);
4485
4486
17
  if (EXPECTED(zv != NULL)) {
4487
14
    zend_function *fbc = Z_FUNC_P(zv);
4488
4489
14
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
4490
0
      init_func_run_time_cache_i(&fbc->op_array);
4491
0
    }
4492
14
    return fbc;
4493
14
  }
4494
3
  return NULL;
4495
17
} /* }}} */
4496
4497
ZEND_API void ZEND_FASTCALL zend_init_func_run_time_cache(zend_op_array *op_array) /* {{{ */
4498
0
{
4499
0
  if (!RUN_TIME_CACHE(op_array)) {
4500
0
    init_func_run_time_cache_i(op_array);
4501
0
  }
4502
0
} /* }}} */
4503
4504
static zend_always_inline void i_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
4505
157k
{
4506
157k
  ZEND_ASSERT(EX(func) == (zend_function*)op_array);
4507
4508
157k
  EX(opline) = op_array->opcodes;
4509
157k
  EX(call) = NULL;
4510
157k
  EX(return_value) = return_value;
4511
4512
157k
  if (op_array->last_var) {
4513
114k
    zend_attach_symbol_table(execute_data);
4514
114k
  }
4515
4516
157k
  if (!ZEND_MAP_PTR(op_array->run_time_cache)) {
4517
156k
    void *ptr;
4518
4519
156k
    ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_HEAP_RT_CACHE);
4520
156k
    ptr = emalloc(op_array->cache_size);
4521
156k
    ZEND_MAP_PTR_INIT(op_array->run_time_cache, ptr);
4522
156k
    memset(ptr, 0, op_array->cache_size);
4523
156k
  }
4524
157k
  EX(run_time_cache) = RUN_TIME_CACHE(op_array);
4525
4526
157k
  EG(current_execute_data) = execute_data;
4527
157k
}
4528
/* }}} */
4529
4530
ZEND_API void zend_init_func_execute_data(zend_execute_data *ex, zend_op_array *op_array, zval *return_value) /* {{{ */
4531
88.0k
{
4532
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4533
  zend_execute_data *orig_execute_data = execute_data;
4534
#endif
4535
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4536
  const zend_op *orig_opline = opline;
4537
#endif
4538
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4539
  execute_data = ex;
4540
#else
4541
88.0k
  zend_execute_data *execute_data = ex;
4542
88.0k
#endif
4543
4544
88.0k
  EX(prev_execute_data) = EG(current_execute_data);
4545
88.0k
  if (!RUN_TIME_CACHE(op_array)) {
4546
7.17k
    init_func_run_time_cache(op_array);
4547
7.17k
  }
4548
88.0k
  i_init_func_execute_data(op_array, return_value, 1 EXECUTE_DATA_CC);
4549
4550
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4551
  EX(opline) = opline;
4552
  opline = orig_opline;
4553
#endif
4554
#if defined(ZEND_VM_FP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
4555
  execute_data = orig_execute_data;
4556
#endif
4557
88.0k
}
4558
/* }}} */
4559
4560
ZEND_API void zend_init_code_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
4561
0
{
4562
0
  EX(prev_execute_data) = EG(current_execute_data);
4563
0
  i_init_code_execute_data(execute_data, op_array, return_value);
4564
0
}
4565
/* }}} */
4566
4567
ZEND_API void zend_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value) /* {{{ */
4568
0
{
4569
0
  if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) {
4570
0
    zend_init_code_execute_data(execute_data, op_array, return_value);
4571
0
  } else {
4572
0
    zend_init_func_execute_data(execute_data, op_array, return_value);
4573
0
  }
4574
0
}
4575
/* }}} */
4576
4577
zend_execute_data *zend_vm_stack_copy_call_frame(zend_execute_data *call, uint32_t passed_args, uint32_t additional_args) /* {{{ */
4578
58
{
4579
58
  zend_execute_data *new_call;
4580
58
  int used_stack = (EG(vm_stack_top) - (zval*)call) + additional_args;
4581
4582
  /* copy call frame into new stack segment */
4583
58
  new_call = zend_vm_stack_extend(used_stack * sizeof(zval));
4584
58
  *new_call = *call;
4585
58
  ZEND_ADD_CALL_FLAG(new_call, ZEND_CALL_ALLOCATED);
4586
4587
58
  if (passed_args) {
4588
10
    zval *src = ZEND_CALL_ARG(call, 1);
4589
10
    zval *dst = ZEND_CALL_ARG(new_call, 1);
4590
100k
    do {
4591
100k
      ZVAL_COPY_VALUE(dst, src);
4592
100k
      passed_args--;
4593
100k
      src++;
4594
100k
      dst++;
4595
100k
    } while (passed_args);
4596
10
  }
4597
4598
  /* delete old call_frame from previous stack segment */
4599
58
  EG(vm_stack)->prev->top = (zval*)call;
4600
4601
  /* delete previous stack segment if it became empty */
4602
58
  if (UNEXPECTED(EG(vm_stack)->prev->top == ZEND_VM_STACK_ELEMENTS(EG(vm_stack)->prev))) {
4603
0
    zend_vm_stack r = EG(vm_stack)->prev;
4604
4605
0
    EG(vm_stack)->prev = r->prev;
4606
0
    efree(r);
4607
0
  }
4608
4609
58
  return new_call;
4610
58
}
4611
/* }}} */
4612
4613
static zend_always_inline zend_generator *zend_get_running_generator(EXECUTE_DATA_D) /* {{{ */
4614
11.5k
{
4615
  /* The generator object is stored in EX(return_value) */
4616
11.5k
  zend_generator *generator = (zend_generator *) EX(return_value);
4617
  /* However control may currently be delegated to another generator.
4618
   * That's the one we're interested in. */
4619
11.5k
  return generator;
4620
11.5k
}
4621
/* }}} */
4622
4623
ZEND_API void zend_unfinished_calls_gc(zend_execute_data *execute_data, zend_execute_data *call, uint32_t op_num, zend_get_gc_buffer *buf) /* {{{ */
4624
570
{
4625
570
  zend_op *opline = EX(func)->op_array.opcodes + op_num;
4626
570
  int level;
4627
570
  int do_exit;
4628
570
  uint32_t num_args;
4629
4630
570
  if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL ||
4631
570
    opline->opcode == ZEND_INIT_FCALL_BY_NAME ||
4632
570
    opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME ||
4633
570
    opline->opcode == ZEND_INIT_DYNAMIC_CALL ||
4634
570
    opline->opcode == ZEND_INIT_USER_CALL ||
4635
570
    opline->opcode == ZEND_INIT_METHOD_CALL ||
4636
570
    opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
4637
570
    opline->opcode == ZEND_NEW)) {
4638
0
    ZEND_ASSERT(op_num);
4639
0
    opline--;
4640
0
  }
4641
4642
636
  do {
4643
    /* find the number of actually passed arguments */
4644
636
    level = 0;
4645
636
    do_exit = 0;
4646
636
    num_args = ZEND_CALL_NUM_ARGS(call);
4647
2.28k
    do {
4648
2.28k
      switch (opline->opcode) {
4649
294
        case ZEND_DO_FCALL:
4650
294
        case ZEND_DO_ICALL:
4651
344
        case ZEND_DO_UCALL:
4652
344
        case ZEND_DO_FCALL_BY_NAME:
4653
344
        case ZEND_CALLABLE_CONVERT:
4654
344
          level++;
4655
344
          break;
4656
572
        case ZEND_INIT_FCALL:
4657
700
        case ZEND_INIT_FCALL_BY_NAME:
4658
700
        case ZEND_INIT_NS_FCALL_BY_NAME:
4659
720
        case ZEND_INIT_DYNAMIC_CALL:
4660
720
        case ZEND_INIT_USER_CALL:
4661
782
        case ZEND_INIT_METHOD_CALL:
4662
792
        case ZEND_INIT_STATIC_METHOD_CALL:
4663
828
        case ZEND_NEW:
4664
828
          if (level == 0) {
4665
484
            num_args = 0;
4666
484
            do_exit = 1;
4667
484
          }
4668
828
          level--;
4669
828
          break;
4670
116
        case ZEND_SEND_VAL:
4671
252
        case ZEND_SEND_VAL_EX:
4672
268
        case ZEND_SEND_VAR:
4673
380
        case ZEND_SEND_VAR_EX:
4674
380
        case ZEND_SEND_FUNC_ARG:
4675
380
        case ZEND_SEND_REF:
4676
380
        case ZEND_SEND_VAR_NO_REF:
4677
380
        case ZEND_SEND_VAR_NO_REF_EX:
4678
380
        case ZEND_SEND_USER:
4679
380
          if (level == 0) {
4680
            /* For named args, the number of arguments is up to date. */
4681
152
            if (opline->op2_type != IS_CONST) {
4682
76
              num_args = opline->op2.num;
4683
76
            }
4684
152
            do_exit = 1;
4685
152
          }
4686
380
          break;
4687
0
        case ZEND_SEND_ARRAY:
4688
0
        case ZEND_SEND_UNPACK:
4689
0
        case ZEND_CHECK_UNDEF_ARGS:
4690
0
          if (level == 0) {
4691
0
            do_exit = 1;
4692
0
          }
4693
0
          break;
4694
2.28k
      }
4695
2.28k
      if (!do_exit) {
4696
1.65k
        opline--;
4697
1.65k
      }
4698
2.28k
    } while (!do_exit);
4699
636
    if (call->prev_execute_data) {
4700
      /* skip current call region */
4701
66
      level = 0;
4702
66
      do_exit = 0;
4703
96
      do {
4704
96
        switch (opline->opcode) {
4705
0
          case ZEND_DO_FCALL:
4706
0
          case ZEND_DO_ICALL:
4707
0
          case ZEND_DO_UCALL:
4708
0
          case ZEND_DO_FCALL_BY_NAME:
4709
0
          case ZEND_CALLABLE_CONVERT:
4710
0
            level++;
4711
0
            break;
4712
56
          case ZEND_INIT_FCALL:
4713
56
          case ZEND_INIT_FCALL_BY_NAME:
4714
56
          case ZEND_INIT_NS_FCALL_BY_NAME:
4715
56
          case ZEND_INIT_DYNAMIC_CALL:
4716
56
          case ZEND_INIT_USER_CALL:
4717
66
          case ZEND_INIT_METHOD_CALL:
4718
66
          case ZEND_INIT_STATIC_METHOD_CALL:
4719
66
          case ZEND_NEW:
4720
66
            if (level == 0) {
4721
66
              do_exit = 1;
4722
66
            }
4723
66
            level--;
4724
66
            break;
4725
96
        }
4726
96
        opline--;
4727
96
      } while (!do_exit);
4728
66
    }
4729
4730
636
    if (EXPECTED(num_args > 0)) {
4731
76
      zval *p = ZEND_CALL_ARG(call, 1);
4732
82
      do {
4733
82
        zend_get_gc_buffer_add_zval(buf, p);
4734
82
        p++;
4735
82
      } while (--num_args);
4736
76
    }
4737
636
    if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) {
4738
78
      zend_get_gc_buffer_add_obj(buf, Z_OBJ(call->This));
4739
78
    }
4740
636
    if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
4741
76
      zval *val;
4742
228
      ZEND_HASH_FOREACH_VAL(call->extra_named_params, val) {
4743
228
        zend_get_gc_buffer_add_zval(buf, val);
4744
228
      } ZEND_HASH_FOREACH_END();
4745
76
    }
4746
636
    if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) {
4747
20
      zend_get_gc_buffer_add_obj(buf, ZEND_CLOSURE_OBJECT(call->func));
4748
20
    }
4749
4750
636
    call = call->prev_execute_data;
4751
636
  } while (call);
4752
570
}
4753
/* }}} */
4754
4755
static void cleanup_unfinished_calls(zend_execute_data *execute_data, uint32_t op_num) /* {{{ */
4756
387k
{
4757
387k
  if (UNEXPECTED(EX(call))) {
4758
6.22k
    zend_execute_data *call = EX(call);
4759
6.22k
    zend_op *opline = EX(func)->op_array.opcodes + op_num;
4760
6.22k
    int level;
4761
6.22k
    int do_exit;
4762
4763
6.22k
    if (UNEXPECTED(opline->opcode == ZEND_INIT_FCALL ||
4764
6.22k
      opline->opcode == ZEND_INIT_FCALL_BY_NAME ||
4765
6.22k
      opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME ||
4766
6.22k
      opline->opcode == ZEND_INIT_DYNAMIC_CALL ||
4767
6.22k
      opline->opcode == ZEND_INIT_USER_CALL ||
4768
6.22k
      opline->opcode == ZEND_INIT_METHOD_CALL ||
4769
6.22k
      opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
4770
6.22k
      opline->opcode == ZEND_INIT_PARENT_PROPERTY_HOOK_CALL ||
4771
6.22k
      opline->opcode == ZEND_NEW)) {
4772
698
      ZEND_ASSERT(op_num);
4773
698
      opline--;
4774
698
    }
4775
4776
6.68k
    do {
4777
      /* If the exception was thrown during a function call there might be
4778
       * arguments pushed to the stack that have to be dtor'ed. */
4779
4780
      /* find the number of actually passed arguments */
4781
6.68k
      level = 0;
4782
6.68k
      do_exit = 0;
4783
17.8k
      do {
4784
17.8k
        switch (opline->opcode) {
4785
1.53k
          case ZEND_DO_FCALL:
4786
1.53k
          case ZEND_DO_ICALL:
4787
1.76k
          case ZEND_DO_UCALL:
4788
1.76k
          case ZEND_DO_FCALL_BY_NAME:
4789
1.76k
          case ZEND_CALLABLE_CONVERT:
4790
1.76k
            level++;
4791
1.76k
            break;
4792
6.46k
          case ZEND_INIT_FCALL:
4793
6.48k
          case ZEND_INIT_FCALL_BY_NAME:
4794
6.58k
          case ZEND_INIT_NS_FCALL_BY_NAME:
4795
6.82k
          case ZEND_INIT_DYNAMIC_CALL:
4796
6.83k
          case ZEND_INIT_USER_CALL:
4797
7.17k
          case ZEND_INIT_METHOD_CALL:
4798
7.33k
          case ZEND_INIT_STATIC_METHOD_CALL:
4799
7.33k
          case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
4800
7.65k
          case ZEND_NEW:
4801
7.65k
            if (level == 0) {
4802
5.89k
              ZEND_CALL_NUM_ARGS(call) = 0;
4803
5.89k
              do_exit = 1;
4804
5.89k
            }
4805
7.65k
            level--;
4806
7.65k
            break;
4807
1.06k
          case ZEND_SEND_VAL:
4808
1.45k
          case ZEND_SEND_VAL_EX:
4809
1.79k
          case ZEND_SEND_VAR:
4810
1.86k
          case ZEND_SEND_VAR_EX:
4811
1.87k
          case ZEND_SEND_FUNC_ARG:
4812
1.89k
          case ZEND_SEND_REF:
4813
1.89k
          case ZEND_SEND_VAR_NO_REF:
4814
1.89k
          case ZEND_SEND_VAR_NO_REF_EX:
4815
1.91k
          case ZEND_SEND_USER:
4816
1.91k
            if (level == 0) {
4817
              /* For named args, the number of arguments is up to date. */
4818
569
              if (opline->op2_type != IS_CONST) {
4819
429
                ZEND_CALL_NUM_ARGS(call) = opline->op2.num;
4820
429
              }
4821
569
              do_exit = 1;
4822
569
            }
4823
1.91k
            break;
4824
82
          case ZEND_SEND_ARRAY:
4825
180
          case ZEND_SEND_UNPACK:
4826
230
          case ZEND_CHECK_UNDEF_ARGS:
4827
230
            if (level == 0) {
4828
219
              do_exit = 1;
4829
219
            }
4830
230
            break;
4831
17.8k
        }
4832
17.8k
        if (!do_exit) {
4833
11.1k
          opline--;
4834
11.1k
        }
4835
17.8k
      } while (!do_exit);
4836
6.68k
      if (call->prev_execute_data) {
4837
        /* skip current call region */
4838
460
        level = 0;
4839
460
        do_exit = 0;
4840
752
        do {
4841
752
          switch (opline->opcode) {
4842
2
            case ZEND_DO_FCALL:
4843
2
            case ZEND_DO_ICALL:
4844
2
            case ZEND_DO_UCALL:
4845
2
            case ZEND_DO_FCALL_BY_NAME:
4846
2
            case ZEND_CALLABLE_CONVERT:
4847
2
              level++;
4848
2
              break;
4849
409
            case ZEND_INIT_FCALL:
4850
409
            case ZEND_INIT_FCALL_BY_NAME:
4851
417
            case ZEND_INIT_NS_FCALL_BY_NAME:
4852
423
            case ZEND_INIT_DYNAMIC_CALL:
4853
423
            case ZEND_INIT_USER_CALL:
4854
450
            case ZEND_INIT_METHOD_CALL:
4855
457
            case ZEND_INIT_STATIC_METHOD_CALL:
4856
457
            case ZEND_INIT_PARENT_PROPERTY_HOOK_CALL:
4857
462
            case ZEND_NEW:
4858
462
              if (level == 0) {
4859
460
                do_exit = 1;
4860
460
              }
4861
462
              level--;
4862
462
              break;
4863
752
          }
4864
752
          opline--;
4865
752
        } while (!do_exit);
4866
460
      }
4867
4868
6.68k
      zend_vm_stack_free_args(EX(call));
4869
4870
6.68k
      if (ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS) {
4871
171
        OBJ_RELEASE(Z_OBJ(call->This));
4872
171
      }
4873
6.68k
      if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
4874
28
        zend_free_extra_named_params(call->extra_named_params);
4875
28
      }
4876
6.68k
      if (call->func->common.fn_flags & ZEND_ACC_CLOSURE) {
4877
53
        zend_object_release(ZEND_CLOSURE_OBJECT(call->func));
4878
6.63k
      } else if (call->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
4879
43
        zend_string_release_ex(call->func->common.function_name, 0);
4880
43
        zend_free_trampoline(call->func);
4881
43
      }
4882
4883
6.68k
      EX(call) = call->prev_execute_data;
4884
6.68k
      zend_vm_stack_free_call_frame(call);
4885
6.68k
      call = EX(call);
4886
6.68k
    } while (call);
4887
6.22k
  }
4888
387k
}
4889
/* }}} */
4890
4891
static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) /* {{{ */
4892
388k
{
4893
388k
  int i;
4894
4895
1.48M
  for (i = 0; i < EX(func)->op_array.last_live_range; i++) {
4896
1.24M
    const zend_live_range *range = &EX(func)->op_array.live_range[i];
4897
1.24M
    if (range->start > op_num) {
4898
      /* further blocks will not be relevant... */
4899
154k
      break;
4900
1.09M
    } else if (op_num < range->end) {
4901
532k
      if (!catch_op_num || catch_op_num >= range->end) {
4902
313k
        uint32_t kind = range->var & ZEND_LIVE_MASK;
4903
313k
        uint32_t var_num = range->var & ~ZEND_LIVE_MASK;
4904
313k
        zval *var = EX_VAR(var_num);
4905
4906
        /* Handle the split range for loop vars */
4907
313k
        if (catch_op_num) {
4908
307k
          zend_op *final_op = EX(func)->op_array.opcodes + range->end;
4909
307k
          if (final_op->extended_value & ZEND_FREE_ON_RETURN && (final_op->opcode == ZEND_FE_FREE || final_op->opcode == ZEND_FREE)) {
4910
39
            if (catch_op_num < range->end + final_op->op2.num) {
4911
32
              continue;
4912
32
            }
4913
39
          }
4914
307k
        }
4915
4916
313k
        if (kind == ZEND_LIVE_TMPVAR) {
4917
1.54k
          zval_ptr_dtor_nogc(var);
4918
311k
        } else if (kind == ZEND_LIVE_NEW) {
4919
307k
          zend_object *obj;
4920
307k
          ZEND_ASSERT(Z_TYPE_P(var) == IS_OBJECT);
4921
307k
          obj = Z_OBJ_P(var);
4922
307k
          zend_object_store_ctor_failed(obj);
4923
307k
          OBJ_RELEASE(obj);
4924
307k
        } else if (kind == ZEND_LIVE_LOOP) {
4925
798
          if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) {
4926
114
            zend_hash_iterator_del(Z_FE_ITER_P(var));
4927
114
          }
4928
798
          zval_ptr_dtor_nogc(var);
4929
3.75k
        } else if (kind == ZEND_LIVE_ROPE) {
4930
135
          zend_string **rope = (zend_string **)var;
4931
135
          const zend_op *last = EX(func)->op_array.opcodes + op_num;
4932
236
          while ((last->opcode != ZEND_ROPE_ADD && last->opcode != ZEND_ROPE_INIT)
4933
135
              || last->result.var != var_num) {
4934
101
            ZEND_ASSERT(last >= EX(func)->op_array.opcodes);
4935
101
            last--;
4936
101
          }
4937
135
          if (last->opcode == ZEND_ROPE_INIT) {
4938
32
            zend_string_release_ex(*rope, 0);
4939
103
          } else {
4940
103
            uint32_t j = last->extended_value;
4941
2.22k
            do {
4942
2.22k
              zend_string_release_ex(rope[j], 0);
4943
2.22k
            } while (j--);
4944
103
          }
4945
3.61k
        } else if (kind == ZEND_LIVE_SILENCE) {
4946
          /* restore previous error_reporting value */
4947
3.61k
          if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
4948
3.55k
              && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) {
4949
32
            EG(error_reporting) = Z_LVAL_P(var);
4950
32
          }
4951
3.61k
        }
4952
313k
      }
4953
532k
    }
4954
1.24M
  }
4955
388k
}
4956
/* }}} */
4957
4958
1.13k
ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data, uint32_t op_num, uint32_t catch_op_num) {
4959
1.13k
  cleanup_unfinished_calls(execute_data, op_num);
4960
1.13k
  cleanup_live_vars(execute_data, op_num, catch_op_num);
4961
1.13k
}
4962
4963
ZEND_API ZEND_ATTRIBUTE_DEPRECATED HashTable *zend_unfinished_execution_gc(zend_execute_data *execute_data, zend_execute_data *call, zend_get_gc_buffer *gc_buffer)
4964
0
{
4965
0
  return zend_unfinished_execution_gc_ex(execute_data, call, gc_buffer, false);
4966
0
}
4967
4968
ZEND_API HashTable *zend_unfinished_execution_gc_ex(zend_execute_data *execute_data, zend_execute_data *call, zend_get_gc_buffer *gc_buffer, bool suspended_by_yield)
4969
7.99k
{
4970
7.99k
  if (!EX(func)) {
4971
135
    return NULL;
4972
135
  }
4973
4974
7.86k
  if (EX_CALL_INFO() & ZEND_CALL_RELEASE_THIS) {
4975
397
    zend_get_gc_buffer_add_obj(gc_buffer, Z_OBJ(execute_data->This));
4976
397
  }
4977
4978
7.86k
  if (EX_CALL_INFO() & ZEND_CALL_CLOSURE) {
4979
1.81k
    zend_get_gc_buffer_add_obj(gc_buffer, ZEND_CLOSURE_OBJECT(EX(func)));
4980
1.81k
  }
4981
4982
7.86k
  if (!ZEND_USER_CODE(EX(func)->common.type)) {
4983
3.42k
    ZEND_ASSERT(!(EX_CALL_INFO() & (ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)));
4984
3.42k
    return NULL;
4985
3.42k
  }
4986
4987
4.44k
  const zend_op_array *op_array = &EX(func)->op_array;
4988
4989
4.44k
  if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) {
4990
4.09k
    uint32_t i, num_cvs = EX(func)->op_array.last_var;
4991
8.28k
    for (i = 0; i < num_cvs; i++) {
4992
4.18k
      zend_get_gc_buffer_add_zval(gc_buffer, EX_VAR_NUM(i));
4993
4.18k
    }
4994
4.09k
  }
4995
4996
4.44k
  if (EX_CALL_INFO() & ZEND_CALL_FREE_EXTRA_ARGS) {
4997
60
    zval *zv = EX_VAR_NUM(op_array->last_var + op_array->T);
4998
60
    const zval *end = zv + (EX_NUM_ARGS() - op_array->num_args);
4999
122
    while (zv != end) {
5000
62
      zend_get_gc_buffer_add_zval(gc_buffer, zv++);
5001
62
    }
5002
60
  }
5003
5004
4.44k
  if (EX_CALL_INFO() & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
5005
0
    zval extra_named_params;
5006
0
    ZVAL_ARR(&extra_named_params, EX(extra_named_params));
5007
0
    zend_get_gc_buffer_add_zval(gc_buffer, &extra_named_params);
5008
0
  }
5009
5010
4.44k
  uint32_t op_num;
5011
4.44k
  if (UNEXPECTED(execute_data->opline->opcode == ZEND_HANDLE_EXCEPTION)) {
5012
0
    op_num = EG(opline_before_exception) - op_array->opcodes;
5013
4.44k
  } else {
5014
4.44k
    op_num = execute_data->opline - op_array->opcodes;
5015
4.44k
  }
5016
4.44k
  ZEND_ASSERT(op_num < op_array->last);
5017
5018
4.44k
  if (call) {
5019
570
    zend_unfinished_calls_gc(execute_data, call, op_num, gc_buffer);
5020
570
  }
5021
5022
4.44k
  if (execute_data->opline != op_array->opcodes) {
5023
4.34k
    uint32_t i;
5024
5.72k
    for (i = 0; i < op_array->last_live_range; i++) {
5025
1.55k
      const zend_live_range *range = &op_array->live_range[i];
5026
1.55k
      if (range->start > op_num) {
5027
173
        break;
5028
1.38k
      } else if (op_num < range->end) {
5029
258
        uint32_t kind = range->var & ZEND_LIVE_MASK;
5030
258
        uint32_t var_num = range->var & ~ZEND_LIVE_MASK;
5031
258
        zval *var = EX_VAR(var_num);
5032
258
        if (kind == ZEND_LIVE_TMPVAR || kind == ZEND_LIVE_LOOP) {
5033
106
          zend_get_gc_buffer_add_zval(gc_buffer, var);
5034
106
        }
5035
258
      }
5036
1.55k
    }
5037
4.34k
  }
5038
5039
4.44k
  if (EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE) {
5040
343
    return execute_data->symbol_table;
5041
4.09k
  } else {
5042
4.09k
    return NULL;
5043
4.09k
  }
5044
4.44k
}
5045
5046
#if ZEND_VM_SPEC
5047
static void zend_swap_operands(zend_op *op) /* {{{ */
5048
29.0k
{
5049
29.0k
  znode_op     tmp;
5050
29.0k
  uint8_t   tmp_type;
5051
5052
29.0k
  tmp          = op->op1;
5053
29.0k
  tmp_type     = op->op1_type;
5054
29.0k
  op->op1      = op->op2;
5055
29.0k
  op->op1_type = op->op2_type;
5056
29.0k
  op->op2      = tmp;
5057
29.0k
  op->op2_type = tmp_type;
5058
5059
#ifdef ZEND_VERIFY_TYPE_INFERENCE
5060
  uint32_t tmp_info;
5061
  tmp_info = op->op1_use_type;
5062
  op->op1_use_type = op->op2_use_type;
5063
  op->op2_use_type = tmp_info;
5064
  tmp_info = op->op1_def_type;
5065
  op->op1_def_type = op->op2_def_type;
5066
  op->op2_def_type = tmp_info;
5067
#endif
5068
29.0k
}
5069
/* }}} */
5070
#endif
5071
5072
static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_string *function, uint32_t num_args) /* {{{ */
5073
1.26k
{
5074
1.26k
  zend_function *fbc;
5075
1.26k
  zval *func;
5076
1.26k
  zend_class_entry *called_scope;
5077
1.26k
  zend_string *lcname;
5078
1.26k
  const char *colon;
5079
5080
1.26k
  if ((colon = zend_memrchr(ZSTR_VAL(function), ':', ZSTR_LEN(function))) != NULL &&
5081
126
    colon > ZSTR_VAL(function) &&
5082
113
    *(colon-1) == ':'
5083
1.26k
  ) {
5084
99
    zend_string *mname;
5085
99
    size_t cname_length = colon - ZSTR_VAL(function) - 1;
5086
99
    size_t mname_length = ZSTR_LEN(function) - cname_length - (sizeof("::") - 1);
5087
5088
99
    lcname = zend_string_init(ZSTR_VAL(function), cname_length, 0);
5089
5090
99
    called_scope = zend_fetch_class_by_name(lcname, NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION);
5091
99
    if (UNEXPECTED(called_scope == NULL)) {
5092
22
      zend_string_release_ex(lcname, 0);
5093
22
      return NULL;
5094
22
    }
5095
5096
77
    mname = zend_string_init(ZSTR_VAL(function) + (cname_length + sizeof("::") - 1), mname_length, 0);
5097
5098
77
    if (called_scope->get_static_method) {
5099
0
      fbc = called_scope->get_static_method(called_scope, mname);
5100
77
    } else {
5101
77
      fbc = zend_std_get_static_method(called_scope, mname, NULL);
5102
77
    }
5103
77
    if (UNEXPECTED(fbc == NULL)) {
5104
5
      if (EXPECTED(!EG(exception))) {
5105
5
        zend_undefined_method(called_scope, mname);
5106
5
      }
5107
5
      zend_string_release_ex(lcname, 0);
5108
5
      zend_string_release_ex(mname, 0);
5109
5
      return NULL;
5110
5
    }
5111
5112
72
    zend_string_release_ex(lcname, 0);
5113
72
    zend_string_release_ex(mname, 0);
5114
5115
72
    if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
5116
15
      zend_non_static_method_call(fbc);
5117
15
      if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
5118
9
        zend_string_release_ex(fbc->common.function_name, 0);
5119
9
        zend_free_trampoline(fbc);
5120
9
      }
5121
15
      return NULL;
5122
15
    }
5123
57
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5124
22
      init_func_run_time_cache(&fbc->op_array);
5125
22
    }
5126
1.16k
  } else {
5127
1.16k
    if (ZSTR_VAL(function)[0] == '\\') {
5128
4
      lcname = zend_string_alloc(ZSTR_LEN(function) - 1, 0);
5129
4
      zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(function) + 1, ZSTR_LEN(function) - 1);
5130
1.15k
    } else {
5131
1.15k
      lcname = zend_string_tolower(function);
5132
1.15k
    }
5133
1.16k
    if (UNEXPECTED((func = zend_hash_find(EG(function_table), lcname)) == NULL)) {
5134
52
      zend_throw_error(NULL, "Call to undefined function %s()", ZSTR_VAL(function));
5135
52
      zend_string_release_ex(lcname, 0);
5136
52
      return NULL;
5137
52
    }
5138
1.11k
    zend_string_release_ex(lcname, 0);
5139
5140
1.11k
    fbc = Z_FUNC_P(func);
5141
1.11k
    if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5142
289
      init_func_run_time_cache(&fbc->op_array);
5143
289
    }
5144
1.11k
    called_scope = NULL;
5145
1.11k
  }
5146
5147
1.16k
  return zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC,
5148
1.16k
    fbc, num_args, called_scope);
5149
1.26k
}
5150
/* }}} */
5151
5152
static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_object *function, uint32_t num_args) /* {{{ */
5153
5.37k
{
5154
5.37k
  zend_function *fbc;
5155
5.37k
  void *object_or_called_scope;
5156
5.37k
  zend_class_entry *called_scope;
5157
5.37k
  zend_object *object;
5158
5.37k
  uint32_t call_info;
5159
5160
5.37k
  if (EXPECTED(function->handlers->get_closure) &&
5161
5.37k
      EXPECTED(function->handlers->get_closure(function, &called_scope, &fbc, &object, 0) == SUCCESS)) {
5162
5163
5.36k
    object_or_called_scope = called_scope;
5164
5.36k
    if (EXPECTED(fbc->common.fn_flags & ZEND_ACC_CLOSURE)) {
5165
      /* Delay closure destruction until its invocation */
5166
5.22k
      GC_ADDREF(ZEND_CLOSURE_OBJECT(fbc));
5167
5.22k
      ZEND_ASSERT(ZEND_ACC_FAKE_CLOSURE == ZEND_CALL_FAKE_CLOSURE);
5168
5.22k
      call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_CLOSURE |
5169
5.22k
        (fbc->common.fn_flags & ZEND_ACC_FAKE_CLOSURE);
5170
5.22k
      if (object) {
5171
1.56k
        call_info |= ZEND_CALL_HAS_THIS;
5172
1.56k
        object_or_called_scope = object;
5173
1.56k
      }
5174
5.22k
    } else {
5175
139
      call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
5176
139
      if (object) {
5177
139
        call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
5178
139
        GC_ADDREF(object); /* For $this pointer */
5179
139
        object_or_called_scope = object;
5180
139
      }
5181
139
    }
5182
5.36k
  } else {
5183
7
    zend_throw_error(NULL, "Object of type %s is not callable", ZSTR_VAL(function->ce->name));
5184
7
    return NULL;
5185
7
  }
5186
5187
5.36k
  if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5188
99
    init_func_run_time_cache(&fbc->op_array);
5189
99
  }
5190
5191
5.36k
  return zend_vm_stack_push_call_frame(call_info,
5192
5.36k
    fbc, num_args, object_or_called_scope);
5193
5.37k
}
5194
/* }}} */
5195
5196
static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_array *function, uint32_t num_args) /* {{{ */
5197
270
{
5198
270
  zend_function *fbc;
5199
270
  void *object_or_called_scope;
5200
270
  uint32_t call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC;
5201
5202
270
  if (zend_hash_num_elements(function) == 2) {
5203
260
    zval *obj;
5204
260
    zval *method;
5205
260
    obj = zend_hash_index_find(function, 0);
5206
260
    method = zend_hash_index_find(function, 1);
5207
5208
260
    if (UNEXPECTED(!obj) || UNEXPECTED(!method)) {
5209
4
      zend_throw_error(NULL, "Array callback has to contain indices 0 and 1");
5210
4
      return NULL;
5211
4
    }
5212
5213
256
    ZVAL_DEREF(obj);
5214
256
    if (UNEXPECTED(Z_TYPE_P(obj) != IS_STRING) && UNEXPECTED(Z_TYPE_P(obj) != IS_OBJECT)) {
5215
6
      zend_throw_error(NULL, "First array member is not a valid class name or object");
5216
6
      return NULL;
5217
6
    }
5218
5219
250
    ZVAL_DEREF(method);
5220
250
    if (UNEXPECTED(Z_TYPE_P(method) != IS_STRING)) {
5221
0
      zend_throw_error(NULL, "Second array member is not a valid method");
5222
0
      return NULL;
5223
0
    }
5224
5225
250
    if (Z_TYPE_P(obj) == IS_STRING) {
5226
151
      zend_class_entry *called_scope = zend_fetch_class_by_name(Z_STR_P(obj), NULL, ZEND_FETCH_CLASS_DEFAULT | ZEND_FETCH_CLASS_EXCEPTION);
5227
5228
151
      if (UNEXPECTED(called_scope == NULL)) {
5229
29
        return NULL;
5230
29
      }
5231
5232
122
      if (called_scope->get_static_method) {
5233
0
        fbc = called_scope->get_static_method(called_scope, Z_STR_P(method));
5234
122
      } else {
5235
122
        fbc = zend_std_get_static_method(called_scope, Z_STR_P(method), NULL);
5236
122
      }
5237
122
      if (UNEXPECTED(fbc == NULL)) {
5238
8
        if (EXPECTED(!EG(exception))) {
5239
8
          zend_undefined_method(called_scope, Z_STR_P(method));
5240
8
        }
5241
8
        return NULL;
5242
8
      }
5243
114
      if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
5244
17
        zend_non_static_method_call(fbc);
5245
17
        if (fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
5246
11
          zend_string_release_ex(fbc->common.function_name, 0);
5247
11
          zend_free_trampoline(fbc);
5248
11
        }
5249
17
        return NULL;
5250
17
      }
5251
97
      object_or_called_scope = called_scope;
5252
99
    } else {
5253
99
      zend_object *object = Z_OBJ_P(obj);
5254
5255
99
      fbc = Z_OBJ_HT_P(obj)->get_method(&object, Z_STR_P(method), NULL);
5256
99
      if (UNEXPECTED(fbc == NULL)) {
5257
7
        if (EXPECTED(!EG(exception))) {
5258
7
          zend_undefined_method(object->ce, Z_STR_P(method));
5259
7
        }
5260
7
        return NULL;
5261
7
      }
5262
5263
92
      if ((fbc->common.fn_flags & ZEND_ACC_STATIC) != 0) {
5264
21
        object_or_called_scope = object->ce;
5265
71
      } else {
5266
71
        call_info |= ZEND_CALL_RELEASE_THIS | ZEND_CALL_HAS_THIS;
5267
71
        GC_ADDREF(object); /* For $this pointer */
5268
71
        object_or_called_scope = object;
5269
71
      }
5270
92
    }
5271
250
  } else {
5272
10
    zend_throw_error(NULL, "Array callback must have exactly two elements");
5273
10
    return NULL;
5274
10
  }
5275
5276
189
  if (EXPECTED(fbc->type == ZEND_USER_FUNCTION) && UNEXPECTED(!RUN_TIME_CACHE(&fbc->op_array))) {
5277
59
    init_func_run_time_cache(&fbc->op_array);
5278
59
  }
5279
5280
189
  return zend_vm_stack_push_call_frame(call_info,
5281
189
    fbc, num_args, object_or_called_scope);
5282
270
}
5283
/* }}} */
5284
5285
94.7k
#define ZEND_FAKE_OP_ARRAY ((zend_op_array*)(intptr_t)-1)
5286
5287
static zend_never_inline zend_op_array* ZEND_FASTCALL zend_include_or_eval(zval *inc_filename_zv, int type) /* {{{ */
5288
92.5k
{
5289
92.5k
  zend_op_array *new_op_array = NULL;
5290
92.5k
  zend_string *tmp_inc_filename;
5291
92.5k
  zend_string *inc_filename = zval_try_get_tmp_string(inc_filename_zv, &tmp_inc_filename);
5292
92.5k
  if (UNEXPECTED(!inc_filename)) {
5293
14
    return NULL;
5294
14
  }
5295
5296
92.5k
  switch (type) {
5297
17
    case ZEND_INCLUDE_ONCE:
5298
2.14k
    case ZEND_REQUIRE_ONCE: {
5299
2.14k
        zend_file_handle file_handle;
5300
2.14k
        zend_string *resolved_path;
5301
5302
2.14k
        resolved_path = zend_resolve_path(inc_filename);
5303
2.14k
        if (EXPECTED(resolved_path)) {
5304
9
          if (zend_hash_exists(&EG(included_files), resolved_path)) {
5305
2
            new_op_array = ZEND_FAKE_OP_ARRAY;
5306
2
            zend_string_release_ex(resolved_path, 0);
5307
2
            break;
5308
2
          }
5309
2.13k
        } else if (UNEXPECTED(EG(exception))) {
5310
12
          break;
5311
2.12k
        } else if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) {
5312
11
          zend_message_dispatcher(
5313
11
            (type == ZEND_INCLUDE_ONCE) ?
5314
9
              ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,
5315
11
              ZSTR_VAL(inc_filename));
5316
11
          break;
5317
2.11k
        } else {
5318
2.11k
          resolved_path = zend_string_copy(inc_filename);
5319
2.11k
        }
5320
5321
2.11k
        zend_stream_init_filename_ex(&file_handle, resolved_path);
5322
2.11k
        if (SUCCESS == zend_stream_open(&file_handle)) {
5323
5324
7
          if (!file_handle.opened_path) {
5325
0
            file_handle.opened_path = zend_string_copy(resolved_path);
5326
0
          }
5327
5328
7
          if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) {
5329
7
            new_op_array = zend_compile_file(&file_handle, (type==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE));
5330
7
          } else {
5331
0
            new_op_array = ZEND_FAKE_OP_ARRAY;
5332
0
          }
5333
2.11k
        } else if (!EG(exception)) {
5334
131
          zend_message_dispatcher(
5335
131
            (type == ZEND_INCLUDE_ONCE) ?
5336
121
              ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,
5337
131
              ZSTR_VAL(inc_filename));
5338
131
        }
5339
2.11k
        zend_destroy_file_handle(&file_handle);
5340
2.11k
        zend_string_release_ex(resolved_path, 0);
5341
2.11k
      }
5342
0
      break;
5343
1.47k
    case ZEND_INCLUDE:
5344
85.8k
    case ZEND_REQUIRE:
5345
85.8k
      if (UNEXPECTED(zend_str_has_nul_byte(inc_filename))) {
5346
93
        zend_message_dispatcher(
5347
93
          (type == ZEND_INCLUDE) ?
5348
90
            ZMSG_FAILED_INCLUDE_FOPEN : ZMSG_FAILED_REQUIRE_FOPEN,
5349
93
            ZSTR_VAL(inc_filename));
5350
93
        break;
5351
93
      }
5352
85.7k
      new_op_array = compile_filename(type, inc_filename);
5353
85.7k
      break;
5354
4.51k
    case ZEND_EVAL: {
5355
4.51k
        char *eval_desc = zend_make_compiled_string_description("eval()'d code");
5356
4.51k
        new_op_array = zend_compile_string(inc_filename, eval_desc, ZEND_COMPILE_POSITION_AFTER_OPEN_TAG);
5357
4.51k
        efree(eval_desc);
5358
4.51k
      }
5359
4.51k
      break;
5360
92.5k
    EMPTY_SWITCH_DEFAULT_CASE()
5361
92.5k
  }
5362
5363
87.8k
  zend_tmp_string_release(tmp_inc_filename);
5364
87.8k
  return new_op_array;
5365
92.5k
}
5366
/* }}} */
5367
5368
static zend_never_inline bool ZEND_FASTCALL zend_fe_reset_iterator(zval *array_ptr, int by_ref OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5369
1.66k
{
5370
1.66k
  zend_class_entry *ce = Z_OBJCE_P(array_ptr);
5371
1.66k
  zend_object_iterator *iter = ce->get_iterator(ce, array_ptr, by_ref);
5372
1.66k
  bool is_empty;
5373
5374
1.66k
  if (UNEXPECTED(!iter) || UNEXPECTED(EG(exception))) {
5375
30
    if (iter) {
5376
0
      OBJ_RELEASE(&iter->std);
5377
0
    }
5378
30
    if (!EG(exception)) {
5379
0
      zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name));
5380
0
    }
5381
30
    ZVAL_UNDEF(EX_VAR(opline->result.var));
5382
30
    return 1;
5383
30
  }
5384
5385
1.63k
  iter->index = 0;
5386
1.63k
  if (iter->funcs->rewind) {
5387
1.63k
    iter->funcs->rewind(iter);
5388
1.63k
    if (UNEXPECTED(EG(exception) != NULL)) {
5389
116
      OBJ_RELEASE(&iter->std);
5390
116
      ZVAL_UNDEF(EX_VAR(opline->result.var));
5391
116
      return 1;
5392
116
    }
5393
1.63k
  }
5394
5395
1.52k
  is_empty = iter->funcs->valid(iter) != SUCCESS;
5396
5397
1.52k
  if (UNEXPECTED(EG(exception) != NULL)) {
5398
63
    OBJ_RELEASE(&iter->std);
5399
63
    ZVAL_UNDEF(EX_VAR(opline->result.var));
5400
63
    return 1;
5401
63
  }
5402
1.45k
  iter->index = -1; /* will be set to 0 before using next handler */
5403
5404
1.45k
  ZVAL_OBJ(EX_VAR(opline->result.var), &iter->std);
5405
1.45k
  Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
5406
5407
1.45k
  return is_empty;
5408
1.52k
}
5409
/* }}} */
5410
5411
static zend_always_inline zend_result _zend_quick_get_constant(
5412
    const zval *key, uint32_t flags, bool check_defined_only OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5413
20.0k
{
5414
20.0k
  zval *zv;
5415
20.0k
  zend_constant *c = NULL;
5416
5417
  /* null/true/false are resolved during compilation, so don't check for them here. */
5418
20.0k
  zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
5419
20.0k
  if (zv) {
5420
1.85k
    c = (zend_constant*)Z_PTR_P(zv);
5421
18.1k
  } else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
5422
146
    key++;
5423
146
    zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
5424
146
    if (zv) {
5425
60
      c = (zend_constant*)Z_PTR_P(zv);
5426
60
    }
5427
146
  }
5428
5429
20.0k
  if (!c) {
5430
18.0k
    if (!check_defined_only) {
5431
18.0k
      zend_throw_error(NULL, "Undefined constant \"%s\"", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)));
5432
18.0k
      ZVAL_UNDEF(EX_VAR(opline->result.var));
5433
18.0k
    }
5434
18.0k
    return FAILURE;
5435
18.0k
  }
5436
5437
1.91k
  if (!check_defined_only) {
5438
1.89k
    ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
5439
1.89k
    if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) {
5440
104
      if (!CONST_IS_RECURSIVE(c)) {
5441
104
        CONST_PROTECT_RECURSION(c);
5442
104
        zend_deprecated_constant(c, c->name);
5443
104
        CONST_UNPROTECT_RECURSION(c);
5444
104
      }
5445
104
      return SUCCESS;
5446
104
    }
5447
1.89k
  }
5448
5449
1.81k
  CACHE_PTR(opline->extended_value, c);
5450
1.81k
  return SUCCESS;
5451
1.91k
}
5452
/* }}} */
5453
5454
static zend_never_inline void ZEND_FASTCALL zend_quick_get_constant(
5455
    const zval *key, uint32_t flags OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5456
19.9k
{
5457
19.9k
  _zend_quick_get_constant(key, flags, 0 OPLINE_CC EXECUTE_DATA_CC);
5458
19.9k
} /* }}} */
5459
5460
static zend_never_inline zend_result ZEND_FASTCALL zend_quick_check_constant(
5461
    const zval *key OPLINE_DC EXECUTE_DATA_DC) /* {{{ */
5462
81
{
5463
81
  return _zend_quick_get_constant(key, 0, 1 OPLINE_CC EXECUTE_DATA_CC);
5464
81
} /* }}} */
5465
5466
static zend_always_inline uint32_t zend_get_arg_offset_by_name(
5467
4.92k
    const zend_function *fbc, const zend_string *arg_name, void **cache_slot) {
5468
  /* Due to closures, the `fbc` address isn't unique if the memory address is reused.
5469
   * The argument info will be however and uniquely positions the arguments.
5470
   * We do support NULL arg_info, so we have to distinguish that from an uninitialized cache slot. */
5471
4.92k
  void *unique_id = (void *) ((uintptr_t) fbc->common.arg_info | 1);
5472
5473
4.92k
  if (EXPECTED(*cache_slot == unique_id)) {
5474
19
    return *(uintptr_t *)(cache_slot + 1);
5475
19
  }
5476
5477
  // TODO: Use a hash table?
5478
4.90k
  uint32_t num_args = fbc->common.num_args;
5479
13.0k
  for (uint32_t i = 0; i < num_args; i++) {
5480
10.2k
    const zend_arg_info *arg_info = &fbc->common.arg_info[i];
5481
10.2k
    if (zend_string_equals(arg_name, arg_info->name)) {
5482
2.13k
      if ((fbc->type == ZEND_USER_FUNCTION
5483
1.62k
        && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE)))
5484
521
       || (fbc->type == ZEND_INTERNAL_FUNCTION
5485
2.12k
        && !(fbc->common.fn_flags & ZEND_ACC_NEVER_CACHE))) {
5486
2.12k
        *cache_slot = unique_id;
5487
2.12k
        *(uintptr_t *)(cache_slot + 1) = i;
5488
2.12k
      }
5489
2.13k
      return i;
5490
2.13k
    }
5491
10.2k
  }
5492
5493
2.76k
  if (fbc->common.fn_flags & ZEND_ACC_VARIADIC) {
5494
2.66k
    if ((fbc->type == ZEND_USER_FUNCTION
5495
2.48k
      && (!fbc->op_array.refcount || !(fbc->op_array.fn_flags & ZEND_ACC_CLOSURE)))
5496
179
     || (fbc->type == ZEND_INTERNAL_FUNCTION
5497
2.66k
      && !(fbc->common.fn_flags & ZEND_ACC_NEVER_CACHE))) {
5498
2.66k
      *cache_slot = unique_id;
5499
2.66k
      *(uintptr_t *)(cache_slot + 1) = fbc->common.num_args;
5500
2.66k
    }
5501
2.66k
    return fbc->common.num_args;
5502
2.66k
  }
5503
5504
98
  return (uint32_t) -1;
5505
2.76k
}
5506
5507
zval * ZEND_FASTCALL zend_handle_named_arg(
5508
    zend_execute_data **call_ptr, zend_string *arg_name,
5509
3.70k
    uint32_t *arg_num_ptr, void **cache_slot) {
5510
3.70k
  zend_execute_data *call = *call_ptr;
5511
3.70k
  const zend_function *fbc = call->func;
5512
3.70k
  uint32_t arg_offset = zend_get_arg_offset_by_name(fbc, arg_name, cache_slot);
5513
3.70k
  if (UNEXPECTED(arg_offset == (uint32_t) -1)) {
5514
95
    zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name));
5515
95
    return NULL;
5516
95
  }
5517
5518
3.60k
  zval *arg;
5519
3.60k
  if (UNEXPECTED(arg_offset == fbc->common.num_args)) {
5520
    /* Unknown named parameter that will be collected into a variadic. */
5521
1.59k
    if (!(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) {
5522
1.11k
      ZEND_ADD_CALL_FLAG(call, ZEND_CALL_HAS_EXTRA_NAMED_PARAMS);
5523
1.11k
      call->extra_named_params = zend_new_array(0);
5524
1.11k
    }
5525
5526
1.59k
    arg = zend_hash_add_empty_element(call->extra_named_params, arg_name);
5527
1.59k
    if (!arg) {
5528
2
      zend_throw_error(NULL, "Named parameter $%s overwrites previous argument",
5529
2
        ZSTR_VAL(arg_name));
5530
2
      return NULL;
5531
2
    }
5532
1.58k
    *arg_num_ptr = arg_offset + 1;
5533
1.58k
    return arg;
5534
1.59k
  }
5535
5536
2.01k
  uint32_t current_num_args = ZEND_CALL_NUM_ARGS(call);
5537
  // TODO: We may wish to optimize the arg_offset == current_num_args case,
5538
  // which is probably common (if the named parameters are in order of declaration).
5539
2.01k
  if (arg_offset >= current_num_args) {
5540
1.32k
    uint32_t new_num_args = arg_offset + 1;
5541
1.32k
    ZEND_CALL_NUM_ARGS(call) = new_num_args;
5542
5543
1.32k
    uint32_t num_extra_args = new_num_args - current_num_args;
5544
1.32k
    zend_vm_stack_extend_call_frame(call_ptr, current_num_args, num_extra_args);
5545
1.32k
    call = *call_ptr;
5546
5547
1.32k
    arg = ZEND_CALL_VAR_NUM(call, arg_offset);
5548
1.32k
    if (num_extra_args > 1) {
5549
841
      zval *zv = ZEND_CALL_VAR_NUM(call, current_num_args);
5550
3.07k
      do {
5551
3.07k
        ZVAL_UNDEF(zv);
5552
3.07k
        zv++;
5553
3.07k
      } while (zv != arg);
5554
841
      ZEND_ADD_CALL_FLAG(call, ZEND_CALL_MAY_HAVE_UNDEF);
5555
841
    }
5556
1.32k
  } else {
5557
690
    arg = ZEND_CALL_VAR_NUM(call, arg_offset);
5558
690
    if (UNEXPECTED(!Z_ISUNDEF_P(arg))) {
5559
51
      zend_throw_error(NULL, "Named parameter $%s overwrites previous argument",
5560
51
        ZSTR_VAL(arg_name));
5561
51
      return NULL;
5562
51
    }
5563
690
  }
5564
5565
1.96k
  *arg_num_ptr = arg_offset + 1;
5566
1.96k
  return arg;
5567
2.01k
}
5568
5569
84
static zend_execute_data *start_fake_frame(zend_execute_data *call, const zend_op *opline) {
5570
84
  zend_execute_data *old_prev_execute_data = call->prev_execute_data;
5571
84
  call->prev_execute_data = EG(current_execute_data);
5572
84
  call->opline = opline;
5573
84
  EG(current_execute_data) = call;
5574
84
  return old_prev_execute_data;
5575
84
}
5576
5577
84
static void end_fake_frame(zend_execute_data *call, zend_execute_data *old_prev_execute_data) {
5578
84
  zend_execute_data *prev_execute_data = call->prev_execute_data;
5579
84
  EG(current_execute_data) = prev_execute_data;
5580
84
  call->prev_execute_data = old_prev_execute_data;
5581
84
  if (UNEXPECTED(EG(exception)) && ZEND_USER_CODE(prev_execute_data->func->common.type)) {
5582
44
    zend_rethrow_exception(prev_execute_data);
5583
44
  }
5584
84
}
5585
5586
802
ZEND_API zend_result ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call) {
5587
802
  zend_function *fbc = call->func;
5588
802
  if (fbc->type == ZEND_USER_FUNCTION) {
5589
518
    zend_op_array *op_array = &fbc->op_array;
5590
518
    uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
5591
3.98k
    for (uint32_t i = 0; i < num_args; i++) {
5592
3.50k
      zval *arg = ZEND_CALL_VAR_NUM(call, i);
5593
3.50k
      if (!Z_ISUNDEF_P(arg)) {
5594
1.51k
        continue;
5595
1.51k
      }
5596
5597
1.99k
      const zend_op *opline = &op_array->opcodes[i];
5598
1.99k
      if (EXPECTED(opline->opcode == ZEND_RECV_INIT)) {
5599
1.97k
        zval *default_value = RT_CONSTANT(opline, opline->op2);
5600
1.97k
        if (Z_OPT_TYPE_P(default_value) == IS_CONSTANT_AST) {
5601
31
          if (UNEXPECTED(!RUN_TIME_CACHE(op_array))) {
5602
6
            init_func_run_time_cache(op_array);
5603
6
          }
5604
5605
31
          void *run_time_cache = RUN_TIME_CACHE(op_array);
5606
31
          zval *cache_val =
5607
31
            (zval *) ((char *) run_time_cache + Z_CACHE_SLOT_P(default_value));
5608
5609
31
          if (Z_TYPE_P(cache_val) != IS_UNDEF) {
5610
            /* We keep in cache only not refcounted values */
5611
0
            ZVAL_COPY_VALUE(arg, cache_val);
5612
31
          } else {
5613
            /* Update constant inside a temporary zval, to make sure the CONSTANT_AST
5614
             * value is not accessible through back traces. */
5615
31
            zval tmp;
5616
31
            ZVAL_COPY(&tmp, default_value);
5617
31
            zend_execute_data *old = start_fake_frame(call, opline);
5618
31
            zend_result ret = zval_update_constant_ex(&tmp, fbc->op_array.scope);
5619
31
            end_fake_frame(call, old);
5620
31
            if (UNEXPECTED(ret == FAILURE)) {
5621
17
              zval_ptr_dtor_nogc(&tmp);
5622
17
              return FAILURE;
5623
17
            }
5624
14
            ZVAL_COPY_VALUE(arg, &tmp);
5625
14
            if (!Z_REFCOUNTED(tmp)) {
5626
14
              ZVAL_COPY_VALUE(cache_val, &tmp);
5627
14
            }
5628
14
          }
5629
1.94k
        } else {
5630
1.94k
          ZVAL_COPY(arg, default_value);
5631
1.94k
        }
5632
1.97k
      } else {
5633
18
        ZEND_ASSERT(opline->opcode == ZEND_RECV);
5634
18
        zend_execute_data *old = start_fake_frame(call, opline);
5635
18
        zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed");
5636
18
        end_fake_frame(call, old);
5637
18
        return FAILURE;
5638
18
      }
5639
1.99k
    }
5640
5641
483
    return SUCCESS;
5642
518
  } else {
5643
284
    if (fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO) {
5644
      /* Magic function, let it deal with it. */
5645
5
      return SUCCESS;
5646
5
    }
5647
5648
279
    uint32_t num_args = ZEND_CALL_NUM_ARGS(call);
5649
914
    for (uint32_t i = 0; i < num_args; i++) {
5650
654
      zval *arg = ZEND_CALL_VAR_NUM(call, i);
5651
654
      if (!Z_ISUNDEF_P(arg)) {
5652
492
        continue;
5653
492
      }
5654
5655
162
      zend_arg_info *arg_info = &fbc->internal_function.arg_info[i];
5656
162
      if (i < fbc->common.required_num_args) {
5657
12
        zend_execute_data *old = start_fake_frame(call, NULL);
5658
12
        zend_argument_error(zend_ce_argument_count_error, i + 1, "not passed");
5659
12
        end_fake_frame(call, old);
5660
12
        return FAILURE;
5661
12
      }
5662
5663
150
      zval default_value;
5664
150
      if (zend_get_default_from_internal_arg_info(&default_value, arg_info) == FAILURE) {
5665
7
        zend_execute_data *old = start_fake_frame(call, NULL);
5666
7
        zend_argument_error(zend_ce_argument_count_error, i + 1,
5667
7
          "must be passed explicitly, because the default value is not known");
5668
7
        end_fake_frame(call, old);
5669
7
        return FAILURE;
5670
7
      }
5671
5672
143
      if (Z_TYPE(default_value) == IS_CONSTANT_AST) {
5673
16
        zend_execute_data *old = start_fake_frame(call, NULL);
5674
16
        zend_result ret = zval_update_constant_ex(&default_value, fbc->common.scope);
5675
16
        end_fake_frame(call, old);
5676
16
        if (ret == FAILURE) {
5677
0
          return FAILURE;
5678
0
        }
5679
16
      }
5680
5681
143
      ZVAL_COPY_VALUE(arg, &default_value);
5682
143
      if (ZEND_ARG_SEND_MODE(arg_info) & ZEND_SEND_BY_REF) {
5683
0
        ZVAL_NEW_REF(arg, arg);
5684
0
      }
5685
143
    }
5686
279
  }
5687
5688
260
  return SUCCESS;
5689
802
}
5690
5691
ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named_params)
5692
395
{
5693
  /* Extra named params may be shared. */
5694
395
  zend_array_release(extra_named_params);
5695
395
}
5696
5697
#if defined(ZEND_VM_IP_GLOBAL_REG) && ((ZEND_VM_KIND == ZEND_VM_KIND_CALL) || (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID))
5698
/* Special versions of functions that sets EX(opline) before calling zend_vm_stack_extend() */
5699
static zend_always_inline zend_execute_data *_zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope) /* {{{ */
5700
{
5701
  zend_execute_data *call = (zend_execute_data*)EG(vm_stack_top);
5702
5703
  ZEND_ASSERT_VM_STACK_GLOBAL;
5704
5705
  if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) {
5706
    EX(opline) = opline; /* this is the only difference */
5707
    call = (zend_execute_data*)zend_vm_stack_extend(used_stack);
5708
    ZEND_ASSERT_VM_STACK_GLOBAL;
5709
    zend_vm_init_call_frame(call, call_info | ZEND_CALL_ALLOCATED, func, num_args, object_or_called_scope);
5710
    return call;
5711
  } else {
5712
    EG(vm_stack_top) = (zval*)((char*)call + used_stack);
5713
    zend_vm_init_call_frame(call, call_info, func, num_args, object_or_called_scope);
5714
    return call;
5715
  }
5716
} /* }}} */
5717
5718
static zend_always_inline zend_execute_data *_zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, void *object_or_called_scope) /* {{{ */
5719
{
5720
  uint32_t used_stack = zend_vm_calc_used_stack(num_args, func);
5721
5722
  return _zend_vm_stack_push_call_frame_ex(used_stack, call_info,
5723
    func, num_args, object_or_called_scope);
5724
} /* }}} */
5725
#else
5726
450k
# define _zend_vm_stack_push_call_frame_ex zend_vm_stack_push_call_frame_ex
5727
4.46k
# define _zend_vm_stack_push_call_frame    zend_vm_stack_push_call_frame
5728
#endif
5729
5730
#ifdef ZEND_VM_TRACE_HANDLERS
5731
# include "zend_vm_trace_handlers.h"
5732
#elif defined(ZEND_VM_TRACE_LINES)
5733
# include "zend_vm_trace_lines.h"
5734
#elif defined(ZEND_VM_TRACE_MAP)
5735
# include "zend_vm_trace_map.h"
5736
#elif defined(ZEND_VERIFY_TYPE_INFERENCE)
5737
# include "zend_verify_type_inference.h"
5738
#endif
5739
5740
#define ZEND_VM_NEXT_OPCODE_EX(check_exception, skip) \
5741
10.0M
  CHECK_SYMBOL_TABLES() \
5742
10.0M
  if (check_exception) { \
5743
5.87M
    OPLINE = EX(opline) + (skip); \
5744
5.87M
  } else { \
5745
4.21M
    ZEND_ASSERT(!EG(exception)); \
5746
4.21M
    OPLINE = opline + (skip); \
5747
4.13M
  } \
5748
10.0M
  ZEND_VM_CONTINUE()
5749
5750
#define ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION() \
5751
5.70M
  ZEND_VM_NEXT_OPCODE_EX(1, 1)
5752
5753
#define ZEND_VM_NEXT_OPCODE() \
5754
4.77M
  ZEND_VM_NEXT_OPCODE_EX(0, 1)
5755
5756
#define ZEND_VM_SET_NEXT_OPCODE(new_op) \
5757
315k
  CHECK_SYMBOL_TABLES() \
5758
315k
  OPLINE = new_op
5759
5760
#define ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op) \
5761
2.01M
  CHECK_SYMBOL_TABLES() \
5762
2.01M
  OPLINE = new_op
5763
5764
#define ZEND_VM_SET_OPCODE(new_op) \
5765
1.07M
  ZEND_VM_SET_OPCODE_NO_INTERRUPT(new_op); \
5766
1.07M
  ZEND_VM_INTERRUPT_CHECK()
5767
5768
#define ZEND_VM_SET_RELATIVE_OPCODE(opline, offset) \
5769
13.0k
  ZEND_VM_SET_OPCODE(ZEND_OFFSET_TO_OPLINE(opline, offset))
5770
5771
879k
#define ZEND_VM_JMP_EX(new_op, check_exception) do { \
5772
879k
    if (check_exception && UNEXPECTED(EG(exception))) { \
5773
0
      HANDLE_EXCEPTION(); \
5774
0
    } \
5775
879k
    ZEND_VM_SET_OPCODE(new_op); \
5776
879k
    ZEND_VM_CONTINUE(); \
5777
879k
  } while (0)
5778
5779
#define ZEND_VM_JMP(new_op) \
5780
106k
  ZEND_VM_JMP_EX(new_op, 1)
5781
5782
#define ZEND_VM_INC_OPCODE() \
5783
2.62k
  OPLINE++
5784
5785
5786
#define ZEND_VM_REPEATABLE_OPCODE \
5787
6.01k
  do {
5788
#define ZEND_VM_REPEAT_OPCODE(_opcode) \
5789
6.01k
  } while (UNEXPECTED((++opline)->opcode == _opcode)); \
5790
5.25k
  OPLINE = opline; \
5791
5.46k
  ZEND_VM_CONTINUE()
5792
321k
#define ZEND_VM_SMART_BRANCH(_result, _check) do { \
5793
321k
    if ((_check) && UNEXPECTED(EG(exception))) { \
5794
131
      OPLINE = EX(opline); \
5795
321k
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
5796
203k
      if (_result) { \
5797
188k
        ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5798
188k
      } else { \
5799
15.5k
        ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5800
15.5k
      } \
5801
203k
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
5802
36.4k
      if (!(_result)) { \
5803
6.28k
        ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5804
30.1k
      } else { \
5805
30.1k
        ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5806
30.1k
      } \
5807
81.1k
    } else { \
5808
81.1k
      ZVAL_BOOL(EX_VAR(opline->result.var), _result); \
5809
81.1k
      ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
5810
81.1k
    } \
5811
321k
    ZEND_VM_CONTINUE(); \
5812
321k
  } while (0)
5813
4.36k
#define ZEND_VM_SMART_BRANCH_JMPZ(_result, _check) do { \
5814
4.36k
    if ((_check) && UNEXPECTED(EG(exception))) { \
5815
0
      OPLINE = EX(opline); \
5816
4.36k
    } else if (_result) { \
5817
1.37k
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5818
2.98k
    } else { \
5819
2.98k
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5820
2.98k
    } \
5821
4.36k
    ZEND_VM_CONTINUE(); \
5822
4.36k
  } while (0)
5823
22.3k
#define ZEND_VM_SMART_BRANCH_JMPNZ(_result, _check) do { \
5824
22.3k
    if ((_check) && UNEXPECTED(EG(exception))) { \
5825
0
      OPLINE = EX(opline); \
5826
22.3k
    } else if (!(_result)) { \
5827
1.95k
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5828
20.3k
    } else { \
5829
20.3k
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5830
20.3k
    } \
5831
22.3k
    ZEND_VM_CONTINUE(); \
5832
22.3k
  } while (0)
5833
1.39k
#define ZEND_VM_SMART_BRANCH_NONE(_result, _check) do { \
5834
1.39k
    ZVAL_BOOL(EX_VAR(opline->result.var), _result); \
5835
1.39k
    ZEND_VM_NEXT_OPCODE_EX(_check, 1); \
5836
1.39k
    ZEND_VM_CONTINUE(); \
5837
1.39k
  } while (0)
5838
126
#define ZEND_VM_SMART_BRANCH_TRUE() do { \
5839
126
    if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
5840
2
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5841
124
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
5842
105
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5843
105
    } else { \
5844
19
      ZVAL_TRUE(EX_VAR(opline->result.var)); \
5845
19
      ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
5846
19
    } \
5847
126
    ZEND_VM_CONTINUE(); \
5848
126
  } while (0)
5849
26.2k
#define ZEND_VM_SMART_BRANCH_TRUE_JMPZ() do { \
5850
26.2k
    ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5851
26.2k
    ZEND_VM_CONTINUE(); \
5852
26.2k
  } while (0)
5853
108k
#define ZEND_VM_SMART_BRANCH_TRUE_JMPNZ() do { \
5854
108k
    ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5855
108k
    ZEND_VM_CONTINUE(); \
5856
108k
  } while (0)
5857
6.01k
#define ZEND_VM_SMART_BRANCH_TRUE_NONE() do { \
5858
6.01k
    ZVAL_TRUE(EX_VAR(opline->result.var)); \
5859
6.01k
    ZEND_VM_NEXT_OPCODE(); \
5860
6.01k
  } while (0)
5861
2.78k
#define ZEND_VM_SMART_BRANCH_FALSE() do { \
5862
2.78k
    if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPNZ|IS_TMP_VAR))) { \
5863
389
      ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5864
2.39k
    } else if (EXPECTED(opline->result_type == (IS_SMART_BRANCH_JMPZ|IS_TMP_VAR))) { \
5865
1.45k
      ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5866
1.45k
    } else { \
5867
942
      ZVAL_FALSE(EX_VAR(opline->result.var)); \
5868
942
      ZEND_VM_SET_NEXT_OPCODE(opline + 1); \
5869
942
    } \
5870
2.78k
    ZEND_VM_CONTINUE(); \
5871
2.78k
  } while (0)
5872
7.65k
#define ZEND_VM_SMART_BRANCH_FALSE_JMPZ() do { \
5873
7.65k
    ZEND_VM_SET_OPCODE(OP_JMP_ADDR(opline + 1, (opline+1)->op2)); \
5874
7.65k
    ZEND_VM_CONTINUE(); \
5875
7.65k
  } while (0)
5876
9.35k
#define ZEND_VM_SMART_BRANCH_FALSE_JMPNZ() do { \
5877
9.35k
    ZEND_VM_SET_NEXT_OPCODE(opline + 2); \
5878
9.35k
    ZEND_VM_CONTINUE(); \
5879
9.35k
  } while (0)
5880
7.12k
#define ZEND_VM_SMART_BRANCH_FALSE_NONE() do { \
5881
7.12k
    ZVAL_FALSE(EX_VAR(opline->result.var)); \
5882
7.12k
    ZEND_VM_NEXT_OPCODE(); \
5883
7.12k
  } while (0)
5884
5885
#ifdef __GNUC__
5886
# define ZEND_VM_GUARD(name) __asm__("#" #name)
5887
#else
5888
# define ZEND_VM_GUARD(name)
5889
#endif
5890
5891
3.07k
#define UNDEF_RESULT() do { \
5892
3.07k
    if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { \
5893
1.47k
      ZVAL_UNDEF(EX_VAR(opline->result.var)); \
5894
1.47k
    } \
5895
3.07k
  } while (0)
5896
5897
/* This callback disables optimization of "vm_stack_data" variable in VM */
5898
ZEND_API void (ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data) = NULL;
5899
5900
#include "zend_vm_execute.h"
5901
5902
ZEND_API zend_result zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler)
5903
0
{
5904
0
  if (opcode != ZEND_USER_OPCODE) {
5905
0
    if (handler == NULL) {
5906
      /* restore the original handler */
5907
0
      zend_user_opcodes[opcode] = opcode;
5908
0
    } else {
5909
0
      zend_user_opcodes[opcode] = ZEND_USER_OPCODE;
5910
0
    }
5911
0
    zend_user_opcode_handlers[opcode] = handler;
5912
0
    return SUCCESS;
5913
0
  }
5914
0
  return FAILURE;
5915
0
}
5916
5917
ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode)
5918
4.09k
{
5919
4.09k
  return zend_user_opcode_handlers[opcode];
5920
4.09k
}
5921
5922
ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data)
5923
0
{
5924
0
  zval *ret;
5925
5926
0
  switch (op_type) {
5927
0
    case IS_CONST:
5928
0
      ret = RT_CONSTANT(opline, *node);
5929
0
      break;
5930
0
    case IS_TMP_VAR:
5931
0
    case IS_VAR:
5932
0
    case IS_CV:
5933
0
      ret = EX_VAR(node->var);
5934
0
      break;
5935
0
    default:
5936
0
      ret = NULL;
5937
0
      break;
5938
0
  }
5939
0
  return ret;
5940
0
}
5941
5942
ZEND_API void zend_return_unwrap_ref(zend_execute_data *execute_data, zval *return_value)
5943
2.92k
{
5944
2.92k
  if (!return_value || !Z_ISREF_P(return_value)) {
5945
351
    return;
5946
351
  }
5947
5948
2.57k
  zend_execute_data *prev_ex = EX(prev_execute_data);
5949
2.57k
  if (!prev_ex || !prev_ex->func || !ZEND_USER_CODE(prev_ex->func->type)) {
5950
136
    return;
5951
136
  }
5952
5953
2.44k
  const zend_op *do_opline = prev_ex->opline;
5954
2.44k
  if (do_opline->result_type != IS_TMP_VAR) {
5955
1.33k
    return;
5956
1.33k
  }
5957
5958
1.10k
  if (do_opline->opcode != ZEND_DO_FCALL
5959
819
   && do_opline->opcode != ZEND_DO_FCALL_BY_NAME
5960
819
   && do_opline->opcode != ZEND_DO_ICALL
5961
819
   && do_opline->opcode != ZEND_DO_UCALL) {
5962
615
    return;
5963
615
  }
5964
5965
494
  zend_unwrap_reference(return_value);
5966
494
}