Skip to content

Remove null byte from anonymous class name #18290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jorgsowa opened this issue Apr 9, 2025 · 3 comments
Open

Remove null byte from anonymous class name #18290

jorgsowa opened this issue Apr 9, 2025 · 3 comments

Comments

@jorgsowa
Copy link
Contributor

jorgsowa commented Apr 9, 2025

Description

I suggest removing the null byte from an anonymous class name, which can be visible in stack traces. Precisely, it's about this line: https://github.com/php/php-src/blob/master/Zend/zend_compile.c#L9024

It causes problems in observability and testing, and requires workarounds. Example I found:

The change is trivial, but it would be BC break.

@nielsdos
Copy link
Member

nielsdos commented Apr 9, 2025

I solved at least some printing related issues (including one in phpdbg) regarding nul bytes in php errors/warnings. If you have a more concrete example of where this is still not done, please share it; otherwise this seems like a needless BC break to me.

@jorgsowa
Copy link
Contributor Author

jorgsowa commented Apr 9, 2025

It's in the exception stack trace.

class Test {
}

try {
    $test = new class() extends Test {
        public function run()
        {
            throw new Exception();
        }
    };
    $test->run();
} catch (Throwable $e) {
    var_dump($e->getTrace());
}

And the result:

array(1) {
  [0]=>
  array(6) {
    ["file"]=>
    string(92) "/path/scratch_2.php"
    ["line"]=>
    int(13)
    ["function"]=>
    string(3) "run"
    ["class"]=>
    string(111) "Test@anonymous�/path/scratch_2.php:7$0"
    ["type"]=>
    string(2) "->"
    ["args"]=>
    array(0) {
    }
  }
}

@nielsdos
Copy link
Member

nielsdos commented Apr 9, 2025

Indeed it's in the backtrace, but it's printed out properly.

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

No branches or pull requests

2 participants