Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ErrorHandler] Handle PHP 8.3 highlight_file function output changes #51586

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

Merged

Conversation

PhilETaylor
Copy link
Contributor

@PhilETaylor PhilETaylor commented Sep 6, 2023

Q A
Branch? 5.4
Bug fix? PHP 8.3 Compatibility
New feature? no
Deprecations? no
License MIT

PHP 8.3 changes the output from the highlight_file function as described here: https://php.watch/versions/8.3/highlight_file-highlight_string-html-changes

I accidentally ran into this head first when using PHP 8.3.0-RC1 in development with Symfony 6.4-dev when my error had no code rendered

Also affected the {{ '/path/to/file.html.twig'|file_excerpt(140,5) }} twig code file_except renderer - easier to replicate with that code just throw it into your twig file with a valid /path/to/file.html.twig - before this PR there would be no output, after this PR the file except would be shown.

Same fix applied to both files.

ScreenShot-2023-09-06-21 42 56

After this fix the code rendered returned.

ScreenShot-2023-09-06-21 29 54

@derrabus
Copy link
Member

derrabus commented Sep 6, 2023

Thank you. Does this affect 5.4 or 6.3 as well? If that's the case, please retarget your PR.

@PhilETaylor
Copy link
Contributor Author

looks like it needs to be 5.4.

@PhilETaylor PhilETaylor changed the base branch from 6.4 to 5.4 September 6, 2023 21:40
@PhilETaylor PhilETaylor changed the base branch from 5.4 to 6.4 September 6, 2023 21:41
@PhilETaylor PhilETaylor force-pushed the php8errorrenderhighlightfile branch from ad10b00 to 5f260a3 Compare September 6, 2023 21:45
@PhilETaylor PhilETaylor changed the base branch from 6.4 to 5.4 September 6, 2023 21:45
@PhilETaylor PhilETaylor force-pushed the php8errorrenderhighlightfile branch from 5f260a3 to b4190db Compare September 6, 2023 21:51
@derrabus derrabus modified the milestones: 6.4, 5.4 Sep 6, 2023
@PhilETaylor PhilETaylor force-pushed the php8errorrenderhighlightfile branch from b4190db to 809cf74 Compare September 6, 2023 21:54
@PhilETaylor
Copy link
Contributor Author

its late and my eyes sleepy, but I think Ive downgraded it ok, and removed short function syntax in my original to be compatible with PHP 7 also. Should be ok to test now.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very important to update Symfony for this BC-break in PHP 8.3. Thanks Phil for taking care of this!

@nicolas-grekas
Copy link
Member

Thank you @PhilETaylor.

@nicolas-grekas nicolas-grekas merged commit 0da9599 into symfony:5.4 Sep 11, 2023
This was referenced Sep 30, 2023
fabpot added a commit that referenced this pull request Jun 15, 2024
… PHP 8.3 (tscni)

This PR was merged into the 5.4 branch.

Discussion
----------

[ErrorHandler] Fix rendered exception code highlighting on PHP 8.3

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #57354
| License       | MIT

#51586 made some mistakes when fixing the use of `highlight_file()` for PHP 8.3:
- It assumed that the inner `<span>` were changed to `<code>`
- It did not properly adjust the pattern for `\n` when splitting the highlighting across multiple lines
- It replaced all spaces with `&nbsp`, including those inside tags, breaking the highlighting entirely

The first two are easy to fix.

The latter one not so much without CSS adjustments. But just changing `white-space: nowrap` to `white-space: pre` would remove the need for that. I'm a bit worried about side effects though and I'm not sure if `CodeExtension` uses separate styling somewhere, but I can't find anything problematic at least.

A test would be a bit cumbersome to add for this, so unless very much preferred I'd rather not spend the time on it.
But at least in manual tests this resolved all the highlighting issues.

Commits
-------

2b46e2a [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3
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.

7 participants