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:51] 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 or any of these characters: space, tab, period (concat), comma, ending square bracket (arrays) and 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 99: 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.
  
rfc/heredoc-scanner-loosening.txt · Last modified: 2018/06/10 10:26 by cmb