Coverage Report

Created: 2025-12-14 06:10

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