Coverage Report

Created: 2026-06-02 06:39

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