rfc:heredoc-scanner-loosening

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:heredoc-scanner-loosening [2014/08/29 12:32] datibbawrfc: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: Draft+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/heredoc-scanner-loosening   * First Published at: http://wiki.php.net/rfc/heredoc-scanner-loosening
  
  
 ===== Introduction ===== ===== Introduction =====
-Currently the rules for ending a heredoc or nowdoc are quite restrictive, requiring a newline after the closing identifier; this makes it more awkward to combine multiple quotations, such as in array declarations or in combination with other operators.+Currently the rules for ending a heredoc or nowdoc are quite restrictive, requiring a newline after the closing identifier; this makes it more awkward to combine multiple quotations, such as in array declarations or with other operators. The [[http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc|manual entry]] for heredocs has a big pink box to explain those intricate details.
  
-This proposal aims to loosen or altogether remove that restriction. +For instance, this is how you would declare an array comprising a heredoc and regular string:
- +
-===== Proposal ===== +
-A fix for the following scenario:+
  
 <code php> <code php>
-eval("return <<<EOS\nfoo\nEOS;");+$strings = [<<<EOS 
 +hello 
 +EOS 
 +, ' world'];
 </code> </code>
  
-//The above just illustrates the issue and doesn't advocate using eval().//+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 use in array constructs:+Currently, this restriction also causes a parse error with code such as this: 
 + 
 +<code php> 
 +return <<<EOS 
 +Foo! 
 +EOS; // <-- file ends here 
 +</code> 
 + 
 +===== Proposal ===== 
 +This proposal aims to lift the current newline restriction and make it less awkward to use heredocs and nowdocs within constructs, such as array declarations:
  
 <code php> <code php>
Line 44: Line 53:
 </code> </code>
  
-Two ways in which this can be achieved are:+The proposal suggests two distinct ways in which this can be achieved:
  
 ==== Loosened restrictions ==== ==== Loosened restrictions ====
-Ends a quotation as soon as a newline is encountered as well as a few extra characters, i.e. a space, tab, period (concat), comma, ending square bracket (arrays) or null byte (end of file).+Ends a quotation when the closing identifier is followed by something that can't be part of an identifier.
  
 ==== Removed restrictions ==== ==== Removed restrictions ====
Line 70: Line 79:
  
 It emits "ENDOFHEREDOC    ;\nENDOFHEREDOC;" and then stop scanning, leading to a parse error on the next line. It emits "ENDOFHEREDOC    ;\nENDOFHEREDOC;" and then stop scanning, leading to a parse error on the next line.
 +
 +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 like this:+Removing the restrictions altogether will cause issues in code such as this:
  
 <code php> <code php>
Line 82: Line 93:
  
 It emits "Foo bar" and then stops scanning, leading to a parse error at "BLA". It emits "Foo bar" and then stops scanning, leading to a parse error at "BLA".
 +
 +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't occur naturally inside the quotation.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 95: Line 108:
 Voting choices will be: Voting choices will be:
   - No, leave the scanner as it is.   - 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 that can't be part of an identifier.
   - Yes, remove the newline restriction altogether.   - Yes, remove the newline restriction altogether.
  
Line 104: 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