rfc:source_files_without_opening_tag
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:source_files_without_opening_tag [2012/04/10 23:32] – [Why is this desirable?] boutell | rfc:source_files_without_opening_tag [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== ABANDONED ====== | ||
+ | |||
+ | I have abandoned this proposal. I have come to feel it changes the spirit of PHP too much, offering too little gain for the degree of unhappiness it inspires and the potential for confusion it creates. I am leaving it here for historical purposes. -Tom Boutell | ||
+ | |||
====== Request for Comments: Source Files Without Opening Tag ====== | ====== Request for Comments: Source Files Without Opening Tag ====== | ||
- | * Version: 1.1 | + | * Version: |
- | * Date: 2012-04-10 | + | * Date: 2012-04-16 |
* Author: Thomas Boutell < | * Author: Thomas Boutell < | ||
* Status: Under Discussion | * Status: Under Discussion | ||
Line 11: | Line 15: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The purpose of this RFC is to provide a way to support source files that do not begin with ''<? | + | The purpose of this RFC is to provide a way to support source files that do not begin with ''<? |
==== Why is this desirable? ==== | ==== Why is this desirable? ==== | ||
Line 22: | Line 26: | ||
2. Tedious. There is a small but real frustration involved in this redundancy. Small but real frustrations can contribute to long-term disenchantment with a programming language. | 2. Tedious. There is a small but real frustration involved in this redundancy. Small but real frustrations can contribute to long-term disenchantment with a programming language. | ||
- | However these same projects and frameworks may advocate the use of "raw HTML" in PHP files intended as templates for rendering pages, forms and the like. This is a longstanding feature of PHP (indeed the original feature of PHP). Support for it should be maintained, and may perhaps be improved in future to address PHP's current limitations as a templating language. This proposal aims not to close any doors in this regard. | + | However these same projects and frameworks may advocate the use of "raw HTML" in PHP files intended as templates for rendering pages, forms and the like. This is a longstanding feature of PHP (indeed the original feature of PHP). Support for it should be maintained, and may perhaps be improved in future to address PHP's current limitations as a templating language. The two modes should not be mutually exclusive as this makes it impossible for code to interoperate. This proposal aims not to close any doors in this regard. |
==== Related RFC ==== | ==== Related RFC ==== | ||
Line 32: | Line 36: | ||
=== Part 1: Enhance the include, include_once, | === Part 1: Enhance the include, include_once, | ||
- | These keywords will be enhanced with a second, optional parameter. | + | These keywords will be enhanced with a second, optional parameter |
The first parameter (the URL/ | The first parameter (the URL/ | ||
Line 54: | Line 58: | ||
| | ||
// Load filename.phpp. This file must consist purely of source code, no <?php or ?> tokens needed or permitted | // Load filename.phpp. This file must consist purely of source code, no <?php or ?> tokens needed or permitted | ||
- | require ' | + | require ' |
// Behaves just like include_once | // Behaves just like include_once | ||
- | include ' | + | include ' |
// Behaves just like require | // Behaves just like require | ||
- | include ' | + | include ' |
// Combine them all: includes only once, with a fatal error on failure, parsing in "code mode" | // Combine them all: includes only once, with a fatal error on failure, parsing in "code mode" | ||
- | include ' | + | include ' |
// Exactly the same as previous example | // Exactly the same as previous example | ||
- | require_once ' | + | require_once ' |
| | ||
=== Part 2: Filename Convention === | === Part 2: Filename Convention === | ||
- | Although this proposal gives implementers flexibility in when and where they use the INCLUDE_CODE_FIRST | + | Although this proposal gives implementers flexibility in when and where they use the INCLUDE_PURE_CODE |
* Files that should be read starting in HTML mode should have a '' | * Files that should be read starting in HTML mode should have a '' | ||
* Files that should be read starting in PHP mode should have a '' | * Files that should be read starting in PHP mode should have a '' | ||
- | However enforcement of this convention is NOT proposed. The choice to apply '' | + | However enforcement of this convention is NOT proposed. The choice to apply '' |
===== Anticipated And Previously Raised Questions ===== | ===== Anticipated And Previously Raised Questions ===== | ||
Line 85: | Line 89: | ||
No. Code that never uses the new keyword will not be affected in any way. The proposal allows autoloaders to load files the old-fashioned way and to recognize when to do so by a simple common convention or by other local conventions as appropriate. | No. Code that never uses the new keyword will not be affected in any way. The proposal allows autoloaders to load files the old-fashioned way and to recognize when to do so by a simple common convention or by other local conventions as appropriate. | ||
- | **" | + | **" |
- | Typically projects that will benefit from the '' | + | Typically projects that will benefit from this flag also have autoloaders to load classes implicitly when they are first used. So '' |
**" | **" | ||
- | Not really. Even in a worst-case scenario where '' | + | Not really. Even in a worst-case scenario where '' |
**" | **" | ||
- | Of course. A choice to use this feature implies a choice to support only the supporting version of PHP or newer. But it'll break cleanly with a clear error message, just like code that tries to use traits or other newer features. That is one of the advantages of using new keywords rather than applying special behavior to file extensions automatically or similar. | + | Of course. A choice to use this feature implies a choice to support only the supporting version of PHP or newer. But it'll break cleanly with a clear error message, just like code that tries to use traits or other newer features. |
- | **" | + | **" |
- | Two reasons: | + | The first version of the proposal did permit this as a compromise. However it did not please anyone. Those who want to write "pure PHP" class files are not interested in switching from code to markup in the middle of a method and are still able to '' |
- | 1. While it is tempting to be a purist about this, those who are creating code generators and the like may sometimes find it useful to leverage HTML mode in a class file (though they also have the option of requiring a regular .php file). It is not the place of this proposal to forbid them from doing what they want if it doesn' | + | **"Why not introduce |
- | 2. It is suspected that the implementation | + | A new keyword was proposed and did not go over well. Enhancing |
- | **" | + | **" |
- | Using new keywords would require doubling | + | While the '' |
+ | **"Why bitwise flags instead of an associative array of options?" | ||
- | ===== Changelog ===== | + | Bitwise flags are faster and also provide built-in error checking: use of a constant not defined by a particular version of PHP will generate a notice. Require statements are something PHP executes quite often, so generating unnecessary arrays and testing array values is an unnecessary performance hit. |
- | | + | **"Why is the AS keyword necessary? Why not a comma?"** |
- | | + | |
+ | Since these keywords are language constructs, not functions, and their parameters | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | * 2012-05-06 Thomas Boutell: formally abandoned by original proponent. | ||
+ | * 2012-04-09 Yasuo Ohgaki: Added related RFC. | ||
+ | * 2012-04-10 Thomas Boutell: removed misleading word " | ||
+ | * 2012-04-10 Thomas Boutell: version 1.1. Replaced '' | ||
+ | * 2012-04-16 Thomas Boutell: added Nikita Popov' | ||
rfc/source_files_without_opening_tag.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1