rfc:heredoc-scanner-loosening
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:heredoc-scanner-loosening [2014/08/29 12:17] – datibbaw | rfc:heredoc-scanner-loosening [2017/09/22 13:28] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2014-08-29 | * Date: 2014-08-29 | ||
* Author: Tjerk Meesters, datibbaw@php.net | * Author: Tjerk Meesters, datibbaw@php.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Currently the rules for ending a heredoc or nowdoc are quite restrictive, | + | Currently the rules for ending a heredoc or nowdoc are quite restrictive, |
- | ===== Proposal ===== | + | For instance, this is how you would declare an array comprising a heredoc and regular string: |
- | A fix for the following scenario: | + | |
<code php> | <code php> | ||
- | eval(" | + | $strings = [<<< |
+ | hello | ||
+ | EOS | ||
+ | , ' world' | ||
</ | </ | ||
- | //The above just illustrates | + | The comma that you would normally put on the same line as the previous element must now be put on the next line. |
- | Allow more liberal | + | Currently, this restriction also causes a parse error with code such as this: |
+ | |||
+ | <code php> | ||
+ | return <<< | ||
+ | Foo! | ||
+ | EOS; // <-- file ends here | ||
+ | </ | ||
+ | |||
+ | ===== Proposal ===== | ||
+ | This proposal aims to lift the current newline restriction and make it less awkward to use heredocs and nowdocs within | ||
<code php> | <code php> | ||
Line 29: | Line 40: | ||
</ | </ | ||
- | Or class constants: | + | Or with other operators (e.g. concatenation): |
<code php> | <code php> | ||
Line 42: | Line 53: | ||
</ | </ | ||
- | Two ways in which this can be achieved | + | The proposal suggests two distinct |
==== Loosened restrictions ==== | ==== Loosened restrictions ==== | ||
- | Ends a quotation | + | Ends a quotation |
==== Removed restrictions ==== | ==== Removed restrictions ==== | ||
Line 68: | Line 79: | ||
It emits " | It emits " | ||
+ | |||
+ | This is a rather extreme example of trying to break the scanner; while not entirely impossible, it's most likely not based on anything one would encounter in the wild. | ||
==== Removed restrictions ==== | ==== Removed restrictions ==== | ||
- | Removing the restrictions altogether will cause issues | + | Removing the restrictions altogether will cause issues |
<code php> | <code php> | ||
Line 80: | Line 93: | ||
It emits "Foo bar" and then stops scanning, leading to a parse error at " | It emits "Foo bar" and then stops scanning, leading to a parse error at " | ||
+ | |||
+ | Although this may seem undesirable behaviour, it should be noted that the developer is in complete control of choosing the name for their enclosures; it's important to choose an enclosure that doesn' | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 92: | Line 107: | ||
Voting choices will be: | Voting choices will be: | ||
- | - No, leave the scanner as it is. | + | |
- | - Yes, loosen the newline restriction with a selected set of characters. | + | - Yes, loosen the newline restriction with characters |
- | - Yes, remove the newline restriction altogether. | + | - Yes, remove the newline restriction altogether. |
This proposal requires a 2/3 majority as it affects the language. | This proposal requires a 2/3 majority as it affects the language. | ||
Line 102: | Line 117: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
The RFC author will provide the patches. | The RFC author will provide the patches. | ||
- |
rfc/heredoc-scanner-loosening.txt · Last modified: 2018/06/10 10:26 by cmb