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

Closed
jorgsowa opened this issue Apr 9, 2025 · 4 comments
Closed

Remove null byte from anonymous class name #18290

jorgsowa opened this issue Apr 9, 2025 · 4 comments
Labels

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.

Copy link

No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you.

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

No branches or pull requests

2 participants