php-src/Zend
DanielEScherzer de785f9127
Fix bad upmerge from GH-18464 (#18666)
This led to recursion being added to but not removed from internal constants.
2025-05-26 12:40:11 -07:00
..
asm Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64 2025-04-21 13:15:43 +02:00
Optimizer Use win32 glob implementation on all platforms (#18164) 2025-05-20 16:20:59 -03:00
tests Merge branch 'PHP-8.4' 2025-05-25 16:51:18 -07:00
bench.php
LICENSE
Makefile.frag Define default RE2C_FLAGS (#14615) 2024-06-24 22:09:04 +02:00
micro_bench.php
README.md
zend.c Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
zend.h PHP-8.3 is now for PHP 8.3.23-dev 2025-05-21 00:39:56 +02:00
Zend.m4 zend_hrtime: Use clock_gettime_nsec_np() for macOS if available (#17089) 2024-12-10 12:19:41 +01:00
zend_alloc.c Add runtime-enabled heap debugging capabilities (#18172) 2025-03-31 17:24:42 +02:00
zend_alloc.h Add gc and shutdown callbacks to ZendMM custom handlers (#13432) 2024-06-19 19:43:57 +02:00
zend_alloc_sizes.h
zend_API.c Reapply GH-17712 with a fix for internal class constants (#18464) 2025-05-25 16:43:36 -07:00
zend_API.h Make empty_fcall_info and empty_fcall_info_cache macros 2025-04-15 12:51:10 +02:00
zend_arena.h Use zend_error_noreturn for E_ERROR consistently 2023-09-14 11:44:55 +02:00
zend_ast.c Merge branch 'PHP-8.4' 2025-05-19 19:08:29 +02:00
zend_ast.h Add (void) cast 2025-03-24 19:35:30 +01:00
zend_atomic.c Add zend_atomic_int (#14242) 2024-05-30 12:53:44 +02:00
zend_atomic.h Add zend_atomic_int (#14242) 2024-05-30 12:53:44 +02:00
zend_attributes.c [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_attributes.h [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_attributes.stub.php [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_attributes_arginfo.h [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_bitset.h Drop misleading comments about undefined behavior (GH-17532) 2025-01-26 22:50:52 +01:00
zend_build.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_builtin_functions.c Add get_error_handler(), get_exception_handler() functions 2025-03-27 16:11:46 +01:00
zend_builtin_functions.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_builtin_functions.stub.php Add get_error_handler(), get_exception_handler() functions 2025-03-27 16:11:46 +01:00
zend_builtin_functions_arginfo.h Add get_error_handler(), get_exception_handler() functions 2025-03-27 16:11:46 +01:00
zend_call_stack.c Remove unused variable (GH-17573) 2025-01-26 17:19:40 +01:00
zend_call_stack.h Fix Clang builds regarding undefined function call 2025-01-20 14:49:25 +01:00
zend_closures.c Zend: Fix reference counting for Closures in const-expr (#17853) 2025-03-27 10:11:44 +01:00
zend_closures.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_closures.stub.php
zend_closures_arginfo.h Fix registration of internal readonly child classes (#15459) 2024-08-24 12:36:54 +02:00
zend_compile.c Reapply GH-17712 with a fix for internal class constants (#18464) 2025-05-25 16:43:36 -07:00
zend_compile.h [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_config.w32.h Use built-ins for addition and subtraction on Windows (GH-17472) 2025-01-15 12:58:12 +01:00
zend_constants.c Fix bad upmerge from GH-18464 (#18666) 2025-05-26 12:40:11 -07:00
zend_constants.h Reapply GH-17712 with a fix for internal class constants (#18464) 2025-05-25 16:43:36 -07:00
zend_constants.stub.php Deprecate E_STRICT constant and remove error level 2024-09-18 14:33:14 +02:00
zend_constants_arginfo.h Deprecate E_STRICT constant and remove error level 2024-09-18 14:33:14 +02:00
zend_cpuinfo.c Fix GH-15292: Dynamic AVX detection is broken for MSVC 2024-08-09 18:11:46 +02:00
zend_cpuinfo.h Merge branch 'PHP-8.3' into PHP-8.4 2025-05-24 22:30:02 +02:00
zend_default_classes.c
zend_dtrace.c
zend_dtrace.d
zend_dtrace.h
zend_enum.c Avoid allocation in zend_enum_get_case_cstr() (#18239) 2025-04-04 18:02:47 +02:00
zend_enum.h zend_enum.c: make a bunch of pointers const (#15932) 2024-09-17 12:57:01 +02:00
zend_enum.stub.php
zend_enum_arginfo.h Implement "support doc comments for internal classes and functions" (#13266) 2024-02-25 08:41:31 +01:00
zend_errors.h Deprecate E_STRICT constant and remove error level 2024-09-18 14:33:14 +02:00
zend_exceptions.c Improve performance of instantiating exceptions/errors (#18442) 2025-05-19 20:24:44 +02:00
zend_exceptions.h Zend: Minor refactorings to zend_exceptions() (#16684) 2024-11-10 21:44:30 +00:00
zend_exceptions.stub.php Add request_parse_body() function 2024-02-08 12:08:07 +01:00
zend_exceptions_arginfo.h Generated arginfo header files: use known strings for prop names when… (#15751) 2024-09-30 13:22:34 +02:00
zend_execute.c [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_execute.h [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_execute_API.c [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_extensions.c Fix printf style issues in Windows specific code (GH-17452) 2025-01-13 11:50:05 +01:00
zend_extensions.h update API/ABI versions 2024-09-25 00:44:02 +09:00
zend_fibers.c Merge branch 'PHP-8.3' 2024-08-28 17:45:49 +02:00
zend_fibers.h Allow fiber switching during destructor execution 2024-07-02 15:00:40 +02:00
zend_fibers.stub.php
zend_fibers_arginfo.h Fix registration of internal readonly child classes (#15459) 2024-08-24 12:36:54 +02:00
zend_float.c Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_float.h Zend/*: fix a bunch of typos (GH-16017) 2024-09-24 10:55:21 +02:00
zend_frameless_function.c Implement stackless internal function calls 2024-02-06 17:42:28 +01:00
zend_frameless_function.h Optimize observers (#13649) 2024-06-15 14:42:27 +02:00
zend_gc.c Merge branch 'PHP-8.4' 2025-03-21 11:48:22 +01:00
zend_gc.h Add non-NULL assertion to zend_get_gc_buffer_add_obj() (#17671) 2025-02-02 19:09:53 +01:00
zend_gdb.c Zend: change uses of sprintf into snprintf 2024-06-14 08:12:03 -07:00
zend_gdb.h
zend_generators.c Merge branch 'PHP-8.3' into PHP-8.4 2024-10-02 12:33:06 +02:00
zend_generators.h Merge branch 'PHP-8.3' into PHP-8.4 2024-10-02 12:33:06 +02:00
zend_generators.stub.php Make ReflectionGenerator::getFunction() legal after generator termination (#14167) 2024-05-21 08:54:51 +02:00
zend_generators_arginfo.h Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
zend_globals.h RFC: Error Backtraces v2 (#17056) 2025-01-29 12:54:23 +01:00
zend_globals_macros.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_hash.c removed <mmintrin.h> (#18414) 2025-04-25 08:26:51 +09:00
zend_hash.h Zend/hash: Add yet more const qualifiers (#18084) 2025-03-18 17:36:40 +00:00
zend_highlight.c [RFC] Property hooks (#13455) 2024-07-14 11:55:03 +02:00
zend_highlight.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_hrtime.c zend_hrtime: Use clock_gettime_nsec_np() for macOS if available (#17089) 2024-12-10 12:19:41 +01:00
zend_hrtime.h Fix Clang style nits (GH-17685) 2025-02-05 14:13:56 +01:00
zend_inheritance.c Merge branch 'PHP-8.4' 2025-05-19 19:22:16 +02:00
zend_inheritance.h Zend/zend_inheritance: Add some const modifiers 2025-04-05 15:47:51 +01:00
zend_ini.c sapi/cli: Extend --ini to print INI settings changed from the builtin default (#17459) 2025-02-05 17:54:52 +01:00
zend_ini.h sapi/cli: Extend --ini to print INI settings changed from the builtin default (#17459) 2025-02-05 17:54:52 +01:00
zend_ini_parser.y Merge branch 'PHP-8.3' 2024-06-28 22:10:23 +02:00
zend_ini_scanner.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_ini_scanner.l small fixes 2023-07-18 08:31:02 +01:00
zend_interfaces.c Remove pointless operations from zend_user_serialize() (#18188) 2025-03-30 11:18:15 +02:00
zend_interfaces.h Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_interfaces.stub.php
zend_interfaces_arginfo.h Generated arginfo header files: remove empty zend_function_entry arrays (#15705) 2024-09-03 23:19:53 +02:00
zend_iterators.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_iterators.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_language_parser.y Fix OSS-Fuzz #416302790 (#18537) 2025-05-12 18:45:01 +02:00
zend_language_scanner.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_language_scanner.l Add (void) cast 2025-03-24 19:35:30 +01:00
zend_lazy_objects.c Fix segfault when evaluating const expr default value of child prop with added hooks 2025-03-23 16:35:04 +01:00
zend_lazy_objects.h Fix zend_get_property_info_for_slot() for lazy objects (#15855) 2024-09-16 16:58:12 +02:00
zend_list.c Merge branch 'PHP-8.1' into PHP-8.2 2023-10-29 21:47:23 +01:00
zend_list.h Fix -Wenum-int-mismatch warnings on gcc 13 2023-04-20 16:04:59 +02:00
zend_llist.c Revert GH-10300 2023-01-16 12:22:54 +01:00
zend_llist.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_long.h Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_map_ptr.h Fix GH-17715: Handle preloaded internal function runtime cache (#17835) 2025-02-24 14:35:47 +01:00
zend_max_execution_timer.c Revert "Merge branch 'PHP-8.3'" 2024-08-20 16:34:52 +02:00
zend_max_execution_timer.h Modify zend_max_execution_timer.h to export the symbols with C format (#16550) 2024-10-24 16:01:31 +02:00
zend_mmap.h
zend_modules.h update API/ABI versions 2024-09-25 00:44:02 +09:00
zend_multibyte.c general signatures discrepencies fixes (#13122) 2024-01-10 22:19:23 +00:00
zend_multibyte.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_multiply.h Implement zend_safe_address() for MSVC 64bit (GH-17679) 2025-02-14 17:37:27 +01:00
zend_object_handlers.c Merge branch 'PHP-8.4' 2025-05-17 11:21:02 +01:00
zend_object_handlers.h Merge branch 'PHP-8.4' 2025-02-24 21:42:21 +01:00
zend_objects.c Fix zend_get_property_info_for_slot() for lazy objects (#15855) 2024-09-16 16:58:12 +02:00
zend_objects.h Lazy objects 2024-08-30 17:30:03 +02:00
zend_objects_API.c Fix prop info fetching from prop slot with added hooks 2025-04-08 18:45:26 +02:00
zend_objects_API.h Fix circumvented added hooks in JIT 2025-02-26 21:26:00 +01:00
zend_observer.c Optimize observers (#13649) 2024-06-15 14:42:27 +02:00
zend_observer.h Optimize observers (#13649) 2024-06-15 14:42:27 +02:00
zend_opcode.c [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_operators.c Fix enum to bool comparison 2024-12-09 17:49:01 +01:00
zend_operators.h Merge branch 'PHP-8.4' 2025-02-03 22:43:24 +01:00
zend_portability.h Building ext/intl fails with MSVC /std:c11 (#17179) 2025-02-20 15:14:58 +01:00
zend_property_hooks.c Fix incorrect dynamic prop offset in hooked prop iterator 2024-12-18 18:47:48 +01:00
zend_property_hooks.h [RFC] Property hooks (#13455) 2024-07-14 11:55:03 +02:00
zend_ptr_stack.c Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_ptr_stack.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_range_check.h
zend_signal.c Mark multple functions as static (#13864) 2024-05-22 13:11:46 +02:00
zend_signal.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_simd.h Added zend_simd.h (#18413) 2025-05-16 15:42:20 +09:00
zend_smart_str.c zend_smart_string: Add smart_string_append_printf() (#18160) 2025-03-27 20:15:25 +01:00
zend_smart_str.h Show enum cases in errors 2024-06-10 22:58:25 +02:00
zend_smart_str_public.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_smart_string.h zend_smart_string: Add smart_string_append_printf() (#18160) 2025-03-27 20:15:25 +01:00
zend_smart_string_public.h Revert GH-10220 2023-01-16 12:27:33 +01:00
zend_sort.c Revert "#include cleanup (#10216)" 2023-01-16 12:29:41 +01:00
zend_sort.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_stack.c Two enums instead of preprocessor macros (#10617) 2023-02-21 15:34:33 +01:00
zend_stack.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_stream.c Revert GH-10279 2023-01-16 12:25:59 +01:00
zend_stream.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_string.c Merge branch 'PHP-8.2' into PHP-8.3 2024-10-11 09:14:10 +02:00
zend_string.h Zend: Resolve self and parent types at compile time (#17755) 2025-02-11 15:15:32 +00:00
zend_strtod.c Merge branch 'PHP-8.4' 2024-11-08 12:28:44 +00:00
zend_strtod.h Remove zend_strtod mutex (#13974) 2024-04-23 11:52:38 +02:00
zend_strtod_int.h Add comments about internal headers (GH-15689) 2024-09-08 16:11:25 +02:00
zend_system_id.c Interrupt while internal frame is on the stack (#14627) 2024-09-05 00:35:55 +02:00
zend_system_id.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_type_info.h Backport fix for HASH/PACKED array inference through MAY_BE_ARRAY_EMPTY flag (#12591) 2023-11-03 10:54:57 +03:00
zend_types.h removed <mmintrin.h> (#18414) 2025-04-25 08:26:51 +09:00
zend_variables.c Fix GH-17442: Engine UAF with reference assign and dtor 2025-01-30 19:43:03 +01:00
zend_variables.h Fix GH-17442: Engine UAF with reference assign and dtor 2025-01-30 19:43:03 +01:00
zend_verify_type_inference.h Zend/*: fix a bunch of typos (GH-16017) 2024-09-24 10:55:21 +02:00
zend_virtual_cwd.c Zend: Voidify virtual_cwd_(de)activate() (#15554) 2024-08-23 15:28:37 +01:00
zend_virtual_cwd.h Merge branch 'PHP-8.3' into PHP-8.4 2024-11-29 22:11:00 +01:00
zend_vm.h Fix header errors when parsed standalone (#14272) 2024-05-20 22:30:38 +02:00
zend_vm_def.h Merge branch 'PHP-8.4' 2025-05-25 16:51:18 -07:00
zend_vm_execute.h Merge branch 'PHP-8.4' 2025-05-25 16:51:18 -07:00
zend_vm_execute.skl Merge branch 'PHP-8.4' 2025-04-21 13:15:50 +02:00
zend_vm_gen.php Pass opline as argument to opcode handlers in CALL VM 2025-04-15 18:51:54 +02:00
zend_vm_handlers.h zend_vm: Add OPcode specialization for === [] (#18571) 2025-05-19 09:36:30 +02:00
zend_vm_opcodes.c [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_vm_opcodes.h [RFC] Add support for attributes on compile-time constants 2025-04-29 11:53:09 -07:00
zend_vm_trace_handlers.h
zend_vm_trace_lines.h
zend_vm_trace_map.h
zend_weakrefs.c Merge branch 'PHP-8.4' 2024-10-15 12:24:01 +02:00
zend_weakrefs.h zend_weakrefs: Add zend_weakrefs_hash_(clean|destroy)() (#16439) 2024-10-14 18:57:08 +02:00
zend_weakrefs.stub.php
zend_weakrefs_arginfo.h Fix registration of internal readonly child classes (#15459) 2024-08-24 12:36:54 +02:00

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