Coverage Report

Created: 2026-06-02 06:36

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