Coverage Report

Created: 2025-12-14 06:09

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