Skip to content

Stdlib: get_object_vars()/get_mangled_object_vars() — uninitialized public properties omitted (ext/standard/var.c) #10846

Description

@PurHur

Summary

get_object_vars() and get_mangled_object_vars() on an object with a declared but uninitialized public property must include that key mapped to NULL, matching Zend. VM returns an empty array (property dropped).

get_class_vars() already returns ['x' => NULL] correctly — only instance export helpers are wrong.

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_get_object_vars_uninitialized.php
php bin/vm.php test/repro/maintainer_gap_get_object_vars_uninitialized.php'
Call Zend PHP 8.2 VM today
get_object_vars(new C) where public $x; array('x' => NULL) array()
get_mangled_object_vars(new C) array('x' => NULL) array()

php-src reference

Implementation (PHP-in-PHP)

  • ext/standard/get_object_vars.php / VmVar.php (or shared property enumerator): walk declared default properties and include public keys even when slot is unset
  • Mirror for get_mangled_object_vars() mangled-name export
  • No new C runtime — reuse existing property metadata from compile/runtime object layout

Done when (php-src-strict)

  • Repro outputs array('x' => NULL) for both functions on VM
  • Private/protected still hidden from global scope (unchanged)
  • Targeted compliance guard in test/compliance/cases/stdlib/

Verification

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_get_object_vars_uninitialized.php

Related: #9419 (get_object_vars TypeError regression), #5203 (property hooks), #1492

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