php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76609 Flexible heredocs should not have special indentation rules
Submitted: 2018-07-11 03:24 UTC Modified: 2018-07-11 18:25 UTC
From: mattacosta at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 7.3.0alpha3 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-07-11 03:24 UTC] mattacosta at gmail dot com
Description:
------------
Flexible heredocs require that indentation only consist of spaces or tabs, but not both. This could be a problem for code embedded in other files.

Instead of requiring that the indentation exactly match the indentation prior to the end label *and* not have mixed whitespace, it should just exactly match the indentation.

Generally speaking, the language shouldn't decide what indentation is good or bad either. The user should.

Test script:
---------------
<!-- This would be aligned if the tab size were 4 instead of 8. -->
<html>
	<body
		text="<?= <<<LABEL
			  3 tabs
			  and
			  2 spaces
			  LABEL?>"
		attr="hello-world">
	</body>
</html>


Expected result:
----------------
<!-- Mixed or not this would be the same. -->
<html>
    <body
        text="3 tabs
and
2 spaces"
        attr="hello-world">
    </body>
</html>

Actual result:
--------------
Parse error: Invalid indentation - tabs and spaces cannot be mixed

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-11 03:31 UTC] requinix@php.net
-Status: Open +Status: Wont fix
 [2018-07-11 03:31 UTC] requinix@php.net
Flexible heredocs was thoroughly discussed.

https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes
> These [unmixed whitespace] constraints have been included because mixing tabs and spaces for indentation is
> harmful to legibility.
 [2018-07-11 09:54 UTC] nikic@php.net
Personally I'd be open to relax this restriction, but you'll need to bring this up on the internals list. As long as the indentation is always the same (and we thus don't run into the question of "what width is a tab character?") we at least have no technical reason to disallow this.
 [2018-07-11 18:25 UTC] mattacosta at gmail dot com
> Personally I'd be open to relax this restriction, but you'll need to bring this up on the internals list.

Sigh, fair enough. This just feels like an overlooked scenario that's definitely in line with the goal of avoiding "the current situation of having indentation levels ruined by these syntaxes".

> As long as the indentation is always the same (and we thus don't run into the question of "what width is a tab character?") we at least have no technical reason to disallow this.

Yeah, a tab in the text would be same width as a tab before the end label so that shouldn't be a problem.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 16 12:01:23 2021 UTC