rfc:phpp
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionLast revision | |||
— | rfc:phpp [2013/05/29 21:11] – mark inactive salathe | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Request for Comments: New File Type for Pure-Code PHP Scripts ====== | ||
+ | * RFC Version: 1.20 | ||
+ | * Target PHP Version: 6.0 | ||
+ | * Date: 2012-04-12 | ||
+ | * Author: Kris Craig < | ||
+ | * Status: Inactive | ||
+ | * First Published at: http:// | ||
+ | |||
+ | |||
+ | ===== Abstract ===== | ||
+ | |||
+ | This RFC proposes the creation of a new .phpp file type and a new .phpf file type. These file types will both be parsed by the webserver as 100% PHP code; that is, all code will be executed //without// <?php and ?> tags. No raw HTML output would be allowed in these scripts using ?>, though echo/print and other output statements will continue to work in those scripts without any restriction. | ||
+ | |||
+ | ===== Background ===== | ||
+ | |||
+ | ==== PHP as a Templating Language ==== | ||
+ | |||
+ | PHP was originally created to operate as server-side code embedded within a block of HTML with the intention of allowing dynamic, conditional output to be directly and easily inserted into HTML pages. | ||
+ | |||
+ | ==== Modern Frameworks and Standards ==== | ||
+ | |||
+ | The web has evolved considerably since the late 1990s when most people' | ||
+ | |||
+ | As the web has evolved, so too have the various methods for developing in it. PHP now largely takes the form of classes and code-only libraries that are hooked from the UI layer of the modern website. | ||
+ | |||
+ | However, many frameworks utilize more " | ||
+ | |||
+ | ==== The Tags ==== | ||
+ | |||
+ | Over the years, people have occasionally called for one of a few fundamental changes to how PHP scripts are executed, typically involving the removal of the <?php and/or ?> tags or changing it so that PHP files default to PHP mode instead of HTML when parsing. | ||
+ | |||
+ | This RFC does **NOT**, in any way, change the way in which .php scripts are parsed, period! | ||
+ | |||
+ | ==== The Webserver ==== | ||
+ | |||
+ | The webserver must be configured so that PHP will be called to execute a file with a given extension (.php), otherwise the code would just be displayed as text. | ||
+ | |||
+ | ===== Current Behavior ===== | ||
+ | |||
+ | The <?php tag, contained within one of these files, tells the webserver to, in essence, " | ||
+ | |||
+ | ===== The Problem ===== | ||
+ | |||
+ | Pure-code PHP files (i.e. PHP scripts that have <?php at the top and never use the ?> tag; thus never " | ||
+ | |||
+ | The first observer might then counter that having to include a <?php tag at the top of every file, while admittedly very low-impact, is tedious and sometimes even forgotten (though not for long if the developer bothers to test his/her own code). | ||
+ | |||
+ | ===== The Solution ===== | ||
+ | |||
+ | It is my view that both of these hypothetical observers are correct. | ||
+ | |||
+ | A .phpp file would behave exactly like a .php file, //except// for the following: | ||
+ | |||
+ | * Instead of defaulting to HTML, everything within the file is parsed as if it was in a <?php tag. | ||
+ | * If ?> tag is reached within one of these files, an E_RECOVERABLE_ERROR will be thrown and those tags, as well as any raw HTML code, will be ignored. | ||
+ | * If a <?php tag is reached within one of these files, an E_NOTICE error will be thrown. | ||
+ | * Any .phpp scripts included by a .phpp file must also adhere to these rules and contain only pure HTML code. | ||
+ | * A regular .php script cannot be included from a .phpp script. | ||
+ | |||
+ | However, there are frameworks and libraries that don't follow a segregated framework but would nonetheless benefit from being able to use PHP-only files. | ||
+ | |||
+ | A .phpf file would behave exactly like a .phpp file, //except// that regular .php scripts //can// be included and are allowed to contain raw ?> content. | ||
+ | |||
+ | ==== Inclusion of Mixed Code ==== | ||
+ | |||
+ | The .phpp file type is generally intended for use with applications that have been designed from the ground-up with MVC code segregation. | ||
+ | |||
+ | The following flow chart shows an example of both the right way and the wrong way to use a .phpp stack: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== Naming Conventions ==== | ||
+ | |||
+ | Obviously, PHP does not rely on file extensions themselves to determine how to parse a script. | ||
+ | |||
+ | ==== Script Inclusion ==== | ||
+ | |||
+ | If you're including a .phpf or .phpp script from within a PHP script, we'll need a way to tell PHP what type of file we're including. | ||
+ | |||
+ | require[(] $script_filename, | ||
+ | |||
+ | Possible values for $script_type: | ||
+ | |||
+ | PHP_SCRIPT_TYPE_NORMAL (0x01) | ||
+ | * If the included file contains PHP code, parse it. | ||
+ | |||
+ | PHP_SCRIPT_TYPE_TAGLESS (0x02) | ||
+ | * Code is assumed to be PHP throughout the script. | ||
+ | |||
+ | PHP_SCRIPT_TYPE_STACK (0x04) | ||
+ | * The $script_type is applied to all child scripts of the one being included. | ||
+ | * Question : Would anyone see value in adding an override constant that, while not recommended, | ||
+ | |||
+ | PHP_SCRIPT_TYPE_CODE_FILE (PHP_SCRIPT_TYPE_NORMAL & PHP_SCRIPT_TYPE_TAGLESS) | ||
+ | * The entire script is assumed to be PHP code and is parsed accordingly. | ||
+ | |||
+ | PHP_SCRIPT_TYPE_CODE_STACK (PHP_SCRIPT_TYPE_NORMAL & PHP_SCRIPT_TYPE_TAGLESS & PHP_SCRIPT_TYPE_STACK) | ||
+ | * The entire script and all its child scripts (i.e. its " | ||
+ | |||
+ | ==== Using " | ||
+ | |||
+ | It has been suggested that, instead of " | ||
+ | |||
+ | ==== Webserver Execution ==== | ||
+ | |||
+ | Ideally, we want .phpf and .phpp files to be able to be directly executed from the browser in addition to include/ | ||
+ | |||
+ | However, script inclusion is the more important priority. | ||
+ | |||
+ | ===== Final Thoughts ===== | ||
+ | |||
+ | I targetted this for PHP 6 since, even though it doesn' | ||
+ | |||
+ | With this new feature, developers will be able to adopt best-practices architectural models with far greater ease. Companies that develop and maintain PHP implementations will be better able to hire designers with little-to-no programming ability and vice versa. | ||
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | Voting has not yet been initiated. | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | Version 1.20 : Language clarifications. | ||
+ | |||
+ | Version 1.10 : Status => Under Discussion. | ||
+ | |||
+ | Version 1.00 : Initial proposal. | ||
rfc/phpp.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1