Coverage Report

Created: 2026-09-14 06:25

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