Skip to content

Stdlib: var_export() — arrays, scalars, and objects (ext/standard/var.c parity) #3594

Closed

Description

@PurHur

Category

stdlib

Problem

var_export() is registered in VM/JIT/AOT but only exports bool and null. Arrays, strings, integers, floats, and objects fatal with LogicException — blocking debug output, return=true capture, and __set_state round-trip used by cache serializers.

Verified May 2026 (Docker php-compiler:22.04-dev):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "var_export([1,2]);"'
# LogicException: var_export() does not support this value type in this compiler build
# ext/standard/var_export.php:87

php-src reference

Repro

Arrays and scalars

<?php
var_export([1, 2]);
echo "\n";
var_export(42);

Zend: array (0 => 1, 1 => 2) and 42
VM: fatal on first line

Objects with __set_state

<?php
class C {
    public int $x = 1;
    public static function __set_state(array $a): self {
        $o = new self();
        $o->x = $a['x'];
        return $o;
    }
}
echo var_export(C::class, true);

Zend: 'C::__set_state(array(...))'
VM: LogicException: var_export() does not support this value type

return=true

<?php
$s = var_export(['a' => 1], true);
echo $s;

Zend: returns export string without echoing
VM: fatal before return

Scope (this repo)

Module Path
VM ext/standard/var_export.php — port recursive export (arrays, scalars, objects)
Helper new ext/standard/VmVarExport.php mirroring Zend php_var_export
JIT/AOT extend exportJit() beyond bool/null
Tests test/compliance/cases/stdlib/var_export*.phpt + AOT fixture

Do not use permanent internal_* shims.

Done when

  • Array/scalar repro matches Zend output on VM
  • var_export($x, true) returns string without echo
  • Objects with __set_state export callable form; without it export (object) array(...) like Zend
  • Circular reference guard throws/recurses like Zend (document subset if deferred)
  • ./script/ci-fast.sh --filter var_export green
  • php script/capability-matrix.php notes full export

Related

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 May 30, 2026
  2. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run (var_export object private/protected property export parity, ZEND_PROP_PURPOSE_VAR_EXPORT)

  3. added a commit that references this issue on Jun 14, 2026
    0455774
  4. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    Merged via #8572.

    Fix: var_export() object branch now uses ZEND_PROP_PURPOSE_VAR_EXPORT semantics (collectVarExportPropertiesForBuiltin) instead of get_object_vars() visibility filtering.

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php test/repro-maintainer/parity_var_export_object_private_props.php
    php bin/vm.php test/repro-maintainer/parity_var_export_object_private_props.php
    php bin/jit.php test/repro-maintainer/parity_var_export_object_private_props.php
    php bin/compile.php -l test/repro-maintainer/parity_var_export_object_private_props.php
    vendor/bin/phpunit --filter var_export_object_private_props
    '

    PHPUnit: OK (4 tests, 4 assertions). VM/JIT output matches Zend for private/protected/public properties.

    Umbrella may stay open for JIT object LLVM lowering (__compiler_var_export still NULL for objects) and other var_export gaps.

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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions