Coverage Report

Created: 2026-02-14 06:52

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