Skip to content

Stdlib: var_export() — objects with __debugInfo must export via hook (ext/standard/var.c) #4854

Closed as not planned

Description

@PurHur

Category

stdlib

Problem

var_export() on objects implementing __debugInfo() should produce a ClassName::__set_state(array(...)) string using the array returned by the magic method (same as Zend). This compiler throws LogicException: var_export() does not support this value type.

var_dump() already documents __debugInfo hook support (#3133, #3259); var_export() object subset (#3594) does not invoke it.

php-src reference

Repro

<?php
class D {
    public function __debugInfo(): array {
        return ['k' => 1];
    }
}
var_export(new D());
echo "\n";
tar -cf - --exclude='.git' --exclude='.llvm' . | docker run --rm -i -m 10g -w /compiler php-compiler:22.04-dev bash -c '
  tar -xf - >/dev/null && source script/php-env.sh &&
  php bin/vm.php repro.php
'
Zend This compiler
Output \D::__set_state(array ('k' => 1,)) LogicException

Scope (this repo)

Done when

  • Repro output matches Zend (modulo whitespace)
  • Objects without __debugInfo behavior unchanged
  • ./script/ci-fast.sh --filter var_export_debug green

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

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 14, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: issue repro already matches Zend PHP 8.2 — var_export() does NOT invoke __debugInfo (only var_dump/print_r do per php.net). Both Zend and VM print empty __set_state(array()) for class D with only __debugInfo. With private property, Zend exports secret=>99 but VM omits it (scope bug) — that is ZEND_PROP_PURPOSE_VAR_EXPORT parity, not __debugInfo. Picking a different issue.

  4. PurHur commented on Jun 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  5. PurHur commented on Jun 15, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: php-src parity confirmed — var_export() does NOT invoke __debugInfo (only var_dump/print_r per php.net language.oop5.magic.php and ext/standard/var.c ZEND_PROP_PURPOSE_VAR_EXPORT). Zend and VM both print empty __set_state(array()) for class D with only __debugInfo. Issue spec contradicts Zend; recommend closing as invalid/wontfix.

  6. PurHur commented on Jun 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  7. PurHur commented on Jun 15, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: Zend parity confirmed — var_export() does not invoke __debugInfo (only var_dump/print_r). VM matches Zend empty __set_state(array()).

  8. PurHur commented on Jul 18, 2026

    @PurHur
    OwnerAuthor

    Invalid premise (confirmed again this run): Zend var_export() does not invoke __debugInfo — only var_dump/print_r do.

    Zend + VM both emit:

    \C::__set_state(array(
       'a' => 1,
    ))
    

    Closing as not planned / incorrect spec. Worker lane A.

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