rfc:linecontrol
This is an old revision of the document!
Request for Comments: Line Markers in PHP
- Version: 1.0
- Date: 2011-08-11
- Author: Gwynne Raskind gwynne@php.net
- Status: Draft
- First Published at: http://wiki.php.net/rfc/linecontrol
This RFC proposes to add linemarkers to PHP at the compiler level.
Introduction
Currently, anything which generates PHP from other input files of any kind must cope with the line numbers and file names in the resulting PHP file being potentially inaccurate.
Why is this needed?
Consider a scenario where a PHP script is only part of a larger file format, in this case PHPT.
--TEST-- Contrived example for an RFC. --FILE-- <?php This is a deliberate syntax error! ?> --EXPECT-- Succulent delights.
Now, run the test:
$ TEST_PHP_EXECUTABLE=`which php` php run-tests.php ./contrived-test.phpt ... $ cat ./contrived-test.log ... ---- ACTUAL OUTPUT Parse error: syntax error, unexpected 'is' (T_STRING) in contrived-test.php on line 2 ---- FAILED $
This RFC would allow run-tests.php, in its PHPT parser, to output something like:
# 4 "./contrived-test.phpt" <?php ...
And then the result of running the test:
$ TEST_PHP_EXECUTABLE=`which php` php run-tests.php ./contrived-test.phpt ... $ cat ./contrived-test.log ... ---- ACTUAL OUTPUT Parse error: syntax error, unexpected 'is' (T_STRING) in contrived-test.phpt on line 5 ---- FAILED $
The error message now locates the error much more usefully. The benefit is more obvious in larger files.
Pro/Con
Pro
- Better identification of the location of error messages
- More control over
FILE
andLINE
macros - Enables useful complex preprocessing
Con
- Interferes with HTML mode
- Potential security implications for malicious manipulation of
FILE
- Questionable interoperation with included files
- May only be useful for CLI applications
Use cases
- Preprocessors in the
cpp(1)
style. - Smarty compiled template files
- PHPT tests
cat something.php | php -
- In general, anything which may produce error-emitting PHP code whose source is not immediately accessible.
Patch
No patch has been written yet, pending a determination of feasability/desirability.
Changelog
- 2011-08-11: Initial revision
rfc/linecontrol.1313035965.txt.gz · Last modified: 2017/09/22 13:28 (external edit)