php/web-php

Code examples no longer copy properly when using Firefox

wrossmann opened this issue · 5 comments

Firefox has recently released a "bugfix" that causes it to copy   as a unicode non-breaking space \xC2\xA0.

All code examples in the manual appear to use   rather than a plain \x20.

The net effect is that anyone using Firefox to browse the manual, and a text editor that does not automatically convert or highlight non-breaking spaces, winds up with broken code and puzzling error messages like 'Parse error: syntax error, unexpected identifier " "'. I have been seeing a number of questions about this crop up on StackOverflow and IRC over the last few weeks, but I wouldn't have guessed that this was the source.

Tested in Firefox 107. Edge and Chrome do not seem to be affected by this.

Both VS Code and PHP Storm display the invisible spaces correctly. I'd expect most IDEs to somehow show these or offer a way to convert them into normal spaces.

But I also agree that the use of nbsp on php.net is not correct. I think we should change it. I guess this will require a simultaneous PR to both web-php and phd.

Actually, the PHP code examples are created by highlight_string() which means that this isn't so easy to fix.

Oof.

I suppose a third $options argument could be added with a flag for DISABLE_NONBREAKING_SPACES or somesuch, but that's a whole PR and release cycle. :/

cmb69 commented

Is this really about the examples on the new minor releases, such as https://www.php.net/releases/8.2/en.php, or is it about examples in the manual proper, e.g. https://www.php.net/manual/en/function.array.php#refsect1-function.array-examples. If the latter, this would be a duplicate of php/phd#71.

It would be the latter, and now that I see it, this is a duplicate of php/phd#71

That said, even though the linked 8.2 example code does not see to use highlight_code() for its syntax highlighting, it does contain   and yet copies cleanly. Which is odd. Though after reading the linked mozilla bugs in the the linked issue it seems that the copying behaviour is fairly complex and context-dependent.