Skip to content

var_dump() and debug_zval_dump() print the full anonymous class name with a raw NUL byte #25418

Open

Description

@jorgsowa

Description

Since 5ed6625 (#23143, %pS migration of ext/standard), var_dump() and debug_zval_dump() print the internal name of an anonymous class, including the NUL byte and the defining file path. PHP 8.5 printed class@anonymous.

The following code:

<?php
$o = new class { public $a = 1; private $p; };
var_dump($o);
print_r($o);

Resulted in this output (\0 is a raw NUL byte):

object(class@anonymous\0/in/test.php:2$0)#1 (2) {
  ["a"]=>
  int(1)
  ["p":"class@anonymous":private]=>
  NULL
}
class@anonymous Object
(
    [a] => 1
    [p:class@anonymous:private] =>
)

But I expected this output instead (as in PHP 8.5):

object(class@anonymous)#1 (2) {
  ["a"]=>
  int(1)
  ["p":"class@anonymous":private]=>
  NULL
}
class@anonymous Object
(
    [a] => 1
    [p:class@anonymous:private] =>
)

The commit changed php_printf("...object(%s)...", ZSTR_VAL(class_name)) to %pS, which prints the whole zend_string. The private property label (zend_unmangle_property_name() + %s) and print_r() still stop at the NUL, so the same dump now shows two different names for one class. The change is in 8.6.0RC6/RC7.

The full name is a deliberate consequence of treating NUL truncation as a bug (#23142), but for dumpers it was not discussed: #23143 had no review, the change is not in NEWS or UPGRADING, and labels and print_r() were left truncated. For 8.6 I suggest restoring %s for the two object headers in ext/standard/var.c (8.5 output); printing the full name consistently in dumps could be discussed for master. @DanielEScherzer, what do you think?

PHP Version

PHP 8.6.0RC7 (PHP-8.6 and master also affected)

Operating System

No response

Activity

  1. jorgsowa commented on Nov 12, 2026

    @jorgsowa
    ContributorAuthor

    I created suggested fix #25419 but feel free to apply your changes. I wanted only to point up regressions in PHP 8.6.

  2. Girgias commented on Nov 12, 2026

    @Girgias
    Member

    I'm in favour of just reverting for 8.6, as this change wasn't really discussed and the fact it was hidden might break quite a few assumptions?

  3. Girgias commented on Nov 12, 2026

    @Girgias
    Member

    Daniel said he'll respond to this later today and would like that any revert be postponed until he has time to reply.

  4. jorgsowa commented on Nov 12, 2026

    @jorgsowa
    ContributorAuthor

    Sure, it's not up to me to make any decisions in this matter. That's not really my area of expertise.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions