Skip to content

Fix truncated anonymous class names in error messages and logs - #25352

Closed
jorgsowa wants to merge 1 commit into
php:PHP-8.6from
jorgsowa:fix-anon-class-name-pS
Closed

jorgsowa wants to merge 1 commit into
php:PHP-8.6from
jorgsowa:fix-anon-class-name-pS

Conversation

@jorgsowa

@jorgsowa jorgsowa commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

I detected this problem while working on PHP Parser in Rust.

Anonymous class names contain a NUL byte (class@anonymous\0file:line$0). Since the %pS migration (#23142), some error messages include the full name, which exposed two problems:

  1. Messages cut off in output. php_error_cb() still wrote the message as a C string in the error log, the HTML fatal error output and the XML-RPC fault, so it stopped at the NUL:

    PHP Fatal error: Class class@anonymous in Standard input code on line 2

The log now writes NUL bytes as \0 (log sinks take C strings), and the HTML/XML-RPC output prints the message by length.

  1. Inconsistent names. Messages not covered by the migration still printed the short name via ZSTR_VAL() / ZEND_FN_SCOPE_NAME(), sometimes both forms in one message:

    Class class@anonymous\0…:2$0 must implement 1 abstract method (class@anonymous::$p::get)

These now use %pS: inheritance errors (abstract method list, #[\Override], access level, static/abstract), private method/destructor calls, private(set) and readonly modification, return type, too few arguments, by-ref unpacking, virtual property unserialization, DOMXPath::__construct() reentry and XMLReader readonly properties.

ext/filter is covered by #23155.

Anonymous class names contain a NUL byte. Since the %pS migration some
error messages print the full name, but the error log, HTML fatal error
and XML-RPC output still formatted the message as a C string, cutting it
at the NUL (e.g. "PHP Fatal error:  Class class@anonymous in ..."). Log
NUL bytes as \0 and print display output by length.

Also use %pS for the remaining Zend, dom and xmlreader messages that
still truncated anonymous class names via ZSTR_VAL().
@jorgsowa jorgsowa closed this in 642899f Nov 11, 2026
arnaud-lb added a commit to jorgsowa/php-src that referenced this pull request Nov 11, 2026
* PHP-8.6:
  Fix error buffer cleanup in phar_open_parsed_phar() (php#25376)
  Fix phpGH-25306: Assertion status == LXB_STATUS_OK in dom_parse_selector when lexbor allocation fails
  Fix AST printing dropping readonly on promoted parameters (phpGH-25207)
  Fix truncated anonymous class names in error messages and logs (phpGH-25352)
  ext/gd: blame the points array when a polygon has too few points
  ext/gd: keep the brush and tile images alive while the destination uses them
  ext/standard/dns.c: drop partially built records in php_parserr()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants