Coverage Report

Created: 2026-06-13 07:01

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