php-src/Zend
Jiří Pudil 38beb44176
[RFC] Extend #[\Override] to target properties (#19061)
RFC: https://wiki.php.net/rfc/override_properties

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2025-08-12 15:18:50 +02:00
..
asm
Optimizer Emit EXT_STMT after each pipe stage, and attach the TMP var that holds the intermediary result (#19377) 2025-08-12 10:26:06 +01:00
tests [RFC] Extend #[\Override] to target properties (#19061) 2025-08-12 15:18:50 +02:00
bench.php
LICENSE
Makefile.frag
micro_bench.php
README.md
zend.c Fix error handling inconsistency with opcache 2025-07-27 11:01:49 +02:00
zend.h Fix error handling inconsistency with opcache 2025-07-27 11:01:49 +02:00
Zend.m4 Autotools: Update ax_check_compile_flag.m4 to serial 11 (#19127) 2025-08-09 02:03:37 +02:00
zend_alloc.c Refresh zend_mm shadow key on fork 2025-07-29 14:00:37 +02:00
zend_alloc.h Refresh zend_mm shadow key on fork 2025-07-29 14:00:37 +02:00
zend_alloc_sizes.h
zend_API.c Various return types and values consolidation (#19418) 2025-08-12 11:28:41 +01:00
zend_API.h tree: use zend_str_has_nul_byte() API (#19336) 2025-07-31 23:57:27 +01:00
zend_arena.h
zend_ast.c Zend: Deprecate non-canonical cast names (#19372) 2025-08-08 21:22:49 +01:00
zend_ast.h Zend/zend_ast: Add const qualifier 2025-08-05 12:43:18 +01:00
zend_atomic.c
zend_atomic.h
zend_attributes.c GH-19153: Validate #[\Attribute] targets (#19154) 2025-08-11 09:05:57 -07:00
zend_attributes.h gen_stub: Add support for attributes on constants in stubs (#18735) 2025-06-05 14:46:46 -07:00
zend_attributes.stub.php [RFC] Extend #[\Override] to target properties (#19061) 2025-08-12 15:18:50 +02:00
zend_attributes_arginfo.h [RFC] Extend #[\Override] to target properties (#19061) 2025-08-12 15:18:50 +02:00
zend_bitset.h
zend_build.h
zend_builtin_functions.c Deprecate the parameter of get_defined_functions() (#19425) 2025-08-09 11:22:43 +01:00
zend_builtin_functions.h
zend_builtin_functions.stub.php gen_stub: Update PHP-Parser to 5.6.0 (#19271) 2025-07-29 07:47:58 -07:00
zend_builtin_functions_arginfo.h gen_stub: Update PHP-Parser to 5.6.0 (#19271) 2025-07-29 07:47:58 -07:00
zend_call_stack.c zend call stack fixing stack limit for macOs arm64. 2025-08-07 08:38:40 +02:00
zend_call_stack.h
zend_closures.c Implement Closure::getCurrent() to retrieve current closure 2025-07-21 16:07:49 +02:00
zend_closures.h
zend_closures.stub.php Implement Closure::getCurrent() to retrieve current closure 2025-07-21 16:07:49 +02:00
zend_closures_arginfo.h Implement Closure::getCurrent() to retrieve current closure 2025-07-21 16:07:49 +02:00
zend_compile.c [RFC] Extend #[\Override] to target properties (#19061) 2025-08-12 15:18:50 +02:00
zend_compile.h [RFC] Extend #[\Override] to target properties (#19061) 2025-08-12 15:18:50 +02:00
zend_config.w32.h
zend_constants.c Make zend_register_*_constant() functions return pointers, use them (#19029) 2025-07-07 12:23:52 -07:00
zend_constants.h Make zend_register_*_constant() functions return pointers, use them (#19029) 2025-07-07 12:23:52 -07:00
zend_constants.stub.php gen_stub: Add support for attributes on constants in stubs (#18735) 2025-06-05 14:46:46 -07:00
zend_constants_arginfo.h Arginfo: avoid using temporary zvals for initializing attribute values (#19141) 2025-07-21 13:33:51 -07:00
zend_cpuinfo.c
zend_cpuinfo.h
zend_default_classes.c
zend_dtrace.c
zend_dtrace.d
zend_dtrace.h
zend_enum.c
zend_enum.h
zend_enum.stub.php
zend_enum_arginfo.h
zend_errors.h
zend_exceptions.c Zend: Exception::__toString() no need to allocate the method name 2025-07-29 21:16:13 +01:00
zend_exceptions.h Zend/zend_exceptions: Add const modifiers 2025-07-29 21:16:13 +01:00
zend_exceptions.stub.php
zend_exceptions_arginfo.h
zend_execute.c tree: use zend_str_has_nul_byte() API (#19336) 2025-07-31 23:57:27 +01:00
zend_execute.h
zend_execute_API.c Zend: refactor zend_call_method_if_exists() API 2025-07-30 12:02:41 +01:00
zend_extensions.c
zend_extensions.h
zend_fibers.c
zend_fibers.h
zend_fibers.stub.php
zend_fibers_arginfo.h
zend_float.c
zend_float.h
zend_frameless_function.c
zend_frameless_function.h
zend_gc.c
zend_gc.h
zend_gdb.c
zend_gdb.h
zend_generators.c Merge branch 'PHP-8.3' into PHP-8.4 2025-07-31 14:29:01 +02:00
zend_generators.h
zend_generators.stub.php
zend_generators_arginfo.h
zend_globals.h Fix error handling inconsistency with opcache 2025-07-27 11:01:49 +02:00
zend_globals_macros.h
zend_hash.c Merge branch 'PHP-8.4' 2025-07-31 21:56:00 +02:00
zend_hash.h
zend_highlight.c
zend_highlight.h
zend_hrtime.c
zend_hrtime.h
zend_inheritance.c [RFC] Extend #[\Override] to target properties (#19061) 2025-08-12 15:18:50 +02:00
zend_inheritance.h
zend_ini.c Implement changes to GH-17951 according to ML discussion 2025-08-04 16:04:25 +02:00
zend_ini.h
zend_ini_parser.y Merge branch 'PHP-8.3' into PHP-8.4 2025-07-04 23:58:33 +02:00
zend_ini_scanner.h
zend_ini_scanner.l Fix -Wuseless-escape warnings emitted by re2c (#19050) 2025-07-07 09:51:25 +02:00
zend_interfaces.c
zend_interfaces.h
zend_interfaces.stub.php
zend_interfaces_arginfo.h
zend_iterators.c RFC: Clone with v2 (#18747) 2025-07-17 21:13:42 +02:00
zend_iterators.h
zend_language_parser.y Deprecate terminating case statements with a semicolon (#19215) 2025-08-11 14:18:06 +02:00
zend_language_scanner.h
zend_language_scanner.l Fix non-canonical casts 2025-08-09 21:40:13 +02:00
zend_lazy_objects.c Zend: constify various parameters in zend_object_handlers and zend_lazy_objects (#19019) 2025-07-03 16:32:10 +02:00
zend_lazy_objects.h Zend: constify various parameters in zend_object_handlers and zend_lazy_objects (#19019) 2025-07-03 16:32:10 +02:00
zend_list.c
zend_list.h
zend_llist.c Remove redundant operations from zend_llist_clean() (#19143) 2025-07-16 09:08:30 +02:00
zend_llist.h
zend_long.h
zend_map_ptr.h
zend_max_execution_timer.c
zend_max_execution_timer.h
zend_mmap.h
zend_modules.h
zend_multibyte.c
zend_multibyte.h
zend_multiply.h Merge branch 'PHP-8.4' 2025-07-22 12:43:57 +02:00
zend_object_handlers.c [RFC] Deprecate returning null from __debugInfo() (#19455) 2025-08-12 11:15:18 +01:00
zend_object_handlers.h RFC: Clone with v2 (#18747) 2025-07-17 21:13:42 +02:00
zend_objects.c RFC: Clone with v2 (#18747) 2025-07-17 21:13:42 +02:00
zend_objects.h RFC: Clone with v2 (#18747) 2025-07-17 21:13:42 +02:00
zend_objects_API.c Merge branch 'PHP-8.3' into PHP-8.4 2025-06-18 21:20:25 +02:00
zend_objects_API.h Zend: Add zend_check_method_accessible() to DRY method visibility checks (#18995) 2025-07-07 21:30:13 +02:00
zend_observer.c
zend_observer.h
zend_opcode.c Emit EXT_STMT after each pipe stage, and attach the TMP var that holds the intermediary result (#19377) 2025-08-12 10:26:06 +01:00
zend_operators.c Merge branch 'PHP-8.4' 2025-07-30 18:14:45 +02:00
zend_operators.h removed ZEND_IS_XDIGIT() (#18926) 2025-06-24 20:40:09 +09:00
zend_portability.h zend: ZEND_NONSTRING for clang >= 20 support (#19193) 2025-07-20 22:27:06 +01:00
zend_property_hooks.c
zend_property_hooks.h
zend_ptr_stack.c
zend_ptr_stack.h
zend_range_check.h
zend_signal.c
zend_signal.h
zend_simd.h
zend_smart_str.c
zend_smart_str.h
zend_smart_str_public.h
zend_smart_string.h
zend_smart_string_public.h
zend_sort.c
zend_sort.h
zend_stack.c
zend_stack.h
zend_stream.c
zend_stream.h
zend_string.c zend_string: Simplify logic in zend_interned_strings_init() (#18922) 2025-06-24 08:50:47 +02:00
zend_string.h Arginfo: add and use known strings for attribute values 2025-07-14 17:31:22 -07:00
zend_strtod.c
zend_strtod.h
zend_strtod_int.h
zend_system_id.c
zend_system_id.h
zend_type_info.h
zend_types.h Merge branch 'PHP-8.4' 2025-07-30 18:14:45 +02:00
zend_variables.c
zend_variables.h
zend_verify_type_inference.h
zend_virtual_cwd.c
zend_virtual_cwd.h
zend_vm.h
zend_vm_def.h Merge branch 'PHP-8.4' 2025-07-30 22:49:08 +02:00
zend_vm_execute.h Merge branch 'PHP-8.4' 2025-07-30 22:49:08 +02:00
zend_vm_execute.skl Introduce zend_vm_opcode_handler_t / zend_vm_opcode_handler_func_t 2025-07-26 13:20:59 +02:00
zend_vm_gen.php Introduce zend_vm_opcode_handler_t / zend_vm_opcode_handler_func_t 2025-07-26 13:20:59 +02:00
zend_vm_handlers.h
zend_vm_opcodes.c
zend_vm_opcodes.h Introduce zend_vm_opcode_handler_t / zend_vm_opcode_handler_func_t 2025-07-26 13:20:59 +02:00
zend_vm_trace_handlers.h
zend_vm_trace_lines.h
zend_vm_trace_map.h
zend_weakrefs.c
zend_weakrefs.h
zend_weakrefs.stub.php
zend_weakrefs_arginfo.h

Zend Engine

Zend memory manager

General

The goal of the new memory manager (available since PHP 5.2) is to reduce memory allocation overhead and speedup memory management.

Debugging

Normal:

sapi/cli/php -r 'leak();'

Zend MM disabled:

USE_ZEND_ALLOC=0 valgrind --leak-check=full sapi/cli/php -r 'leak();'

Shared extensions

Since PHP 5.3.11 it is possible to prevent shared extensions from unloading so that valgrind can correctly track the memory leaks in shared extensions. For this there is the ZEND_DONT_UNLOAD_MODULES environment variable. If set, then DL_UNLOAD() is skipped during the shutdown of shared extensions.

ZEND_VM

ZEND_VM architecture allows specializing opcode handlers according to op_type fields and using different execution methods (call threading, switch threading and direct threading). As a result ZE2 got more than 20% speedup on raw PHP code execution (with specialized executor and direct threading execution method). As in most PHP applications raw execution speed isn't the limiting factor but system calls and database calls are, your mileage with this patch will vary.

Most parts of the old zend_execute.c go into zend_vm_def.h. Here you can find opcode handlers and helpers. The typical opcode handler template looks like this:

ZEND_VM_HANDLER(<OPCODE-NUMBER>, <OPCODE>, <OP1_TYPES>, <OP2_TYPES>)
{
    <HANDLER'S CODE>
}

<OPCODE-NUMBER> is a opcode number (0, 1, ...) <OPCODE> is an opcode name (ZEN_NOP, ZEND_ADD, :) <OP1_TYPES> and <OP2_TYPES> are masks for allowed operand op_types. Specializer will generate code only for defined combination of types. You can use any combination of the following op_types UNUSED, CONST, VAR, TMP and CV also you can use ANY mask to disable specialization according operand's op_type. <HANDLER'S CODE> is a handler's code itself. For most handlers it stills the same as in old zend_execute.c, but now it uses macros to access opcode operands and some internal executor data.

You can see the conformity of new macros to old code in the following list:

EXECUTE_DATA
    execute_data
ZEND_VM_DISPATCH_TO_HANDLER(<OP>)
    return <OP>_helper(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_DISPATCH_TO_HELPER(<NAME>)
    return <NAME>(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_DISPATCH_TO_HELPER_EX(<NAME>,<PARAM>,<VAL>)
    return <NAME>(<VAL>, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
ZEND_VM_CONTINUE()
    return 0
ZEND_VM_NEXT_OPCODE()
    NEXT_OPCODE()
ZEND_VM_SET_OPCODE(<TARGET>
    SET_OPCODE(<TARGET>
ZEND_VM_INC_OPCODE()
    INC_OPCOD()
ZEND_VM_RETURN_FROM_EXECUTE_LOOP()
    RETURN_FROM_EXECUTE_LOOP()
ZEND_VM_C_LABEL(<LABEL>):
    <LABEL>:
ZEND_VM_C_GOTO(<LABEL>)
    goto <LABEL>
OP<X>_TYPE
    opline->op<X>.op_type
GET_OP<X>_ZVAL_PTR(<TYPE>)
    get_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_ZVAL_PTR_PTR(<TYPE>)
    get_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_OBJ_ZVAL_PTR(<TYPE>)
    get_obj_zval_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
GET_OP<X>_OBJ_ZVAL_PTR_PTR(<TYPE>)
    get_obj_zval_ptr_ptr(&opline->op<X>, EX(Ts), &free_op<X>, <TYPE>)
IS_OP<X>_TMP_FREE()
    IS_TMP_FREE(free_op<X>)
FREE_OP<X>()
    FREE_OP(free_op<X>)
FREE_OP<X>_IF_VAR()
    FREE_VAR(free_op<X>)
FREE_OP<X>_VAR_PTR()
    FREE_VAR_PTR(free_op<X>)

Executor's helpers can be defined without parameters or with one parameter. This is done with the following constructs:

ZEND_VM_HELPER(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>)
{
    <HELPER'S CODE>
}

ZEND_VM_HELPER_EX(<HELPER-NAME>, <OP1_TYPES>, <OP2_TYPES>, <PARAM_SPEC>)
{
    <HELPER'S CODE>
}

The executors code is generated by the PHP script zend_vm_gen.php. It uses zend_vm_def.h and zend_vm_execute.skl as input and produces zend_vm_opcodes.h and zend_vm_execute.h. The first file is a list of opcode definitions. It is included from zend_compile.h. The second one is an executor code itself. It is included from zend_execute.c.

zend_vm_gen.php can produce different kind of executors. You can select a different opcode threading model using --with-vm-kind=CALL|SWITCH|GOTO|HYBRID. You can disable opcode specialization using --without-specializer. At last you can debug the executor using the original zend_vm_def.h or the generated zend_vm_execute.h file. Debugging with the original file requires the --with-lines option. By default, Zend Engine uses the following command to generate the executor:

# Default VM kind is HYBRID
php zend_vm_gen.php --with-vm-kind=HYBRID