Skip to content

Stdlib: define() object constant — dynamic properties null not stored values (ext/standard/basic_functions.c) #17676

Description

@PurHur

Category

stdlib · php-src-strict

Problem

define() accepts an object value, but materialized properties are empty on read. Zend stores and returns dynamic property values on the constant object; this compiler loses them (property reads yield empty values / wrong json_encode / empty get_object_vars).

Repro Zend 8.2+ VM (2026-07-10)
define('MY_OBJ', (object)['x'=>1,'y'=>2]); MY_OBJ->x 1 empty / (object) array()
json_encode(MY_OBJ) {"x":1,"y":2} {"x":null,"y":null}
get_object_vars(MY_OBJ) ['x'=>1,'y'=>2] []

php-src reference

PHP implementation target

  • ext/standard/define.php (or equivalent lowering) — preserve object dynamic properties when registering user constants; avoid scalarizing object slots to empty stdClass
  • Shared VM constant table path used by bareword/constant() resolution

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_define_object_constant.php'

Done when

  • test/repro/maintainer_gap_define_object_constant.php prints ok on VM/JIT/AOT
  • Compliance guard under test/compliance/cases/standard/define_object_constant.phpt
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 10, 2026
  2. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  4. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #17676, #17693, #17680)

  5. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #17703.

    Verification (VM):

    php bin/vm.php test/repro/maintainer_gap_define_object_constant.php  # #17676 → ok
    php bin/vm.php test/repro/maintainer_gap_ldap_extension_loaded_phantom.php  # #17680 → ok
    PHP_COMPILER_PROFILE=8.4 php bin/vm.php test/repro-maintainer/issue_readonly_function.php  # #17693 → true + readonly semantics
    ./script/phpunit.sh --filter define_object_constant
  6. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Focused VM fix pushed in PR #17704 (materialize detached object constants, prescan skip for (object)[...] define values, cast detach, temp-release refcount fix).

    Verification (VM):
    ```bash
    php bin/vm.php test/repro/maintainer_gap_define_object_constant.php # ok
    php bin/vm.php test/compliance/cases/stdlib/define_object_constant.phpt # ok
    phpunit --filter define_object_constant # OK (2 tests)
    ```

    AOT compile for this repro remains a follow-up (JIT runtime user-constant fetch + array-literal IR). Overlaps batch PR #17703 — prefer one merge path for #17676.

  7. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #17704.

    Verification:

    php bin/vm.php test/repro/maintainer_gap_define_object_constant.php
    # ok
    
    php bin/compile.php -l test/repro/maintainer_gap_define_object_constant.php
    # exit 0

    Root cause: define('MY_OBJ', (object)[...]) stored shallow/shared object handles; dead temp slot cleanup double-released constant objects after property reads.

    Fix: Deep EnumCaseSupport::materializeConstantValue() + ClassConstMaterializer::detachConstantValue() for object constants; prescan skips inner array for (object)[...]; temp release no longer double-drops refcount on constant objects (userConstantReferencesObjectId guard).

    php-src: ext/standard/basic_functions.c, Zend/zend_constants.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions