[RFC] Line markers in PHP

php.internals

Gwynne Raskind

15 years ago
I've just created a new RFC, https://wiki.php.net/rfc/linecontrol , regarding adding cpp(1)'s linemarkers to PHP. Discussion is invited. -- Gwynne

Nikita Popov

15 years ago
In my eyes this change isn't necessary and if it is, not with this syntax. First the syntax: PHP is not C, we do not have preprocessing instructions using hash notation. Such a syntax seems unfamiliar in PHP. Additionally # is already used for single line comments so there's actually is no backwards compatability: Old code that accidentally was of your proposed form would trigger a line marker, potentially causing much confusion when debugging. If we really do need such a feature it should follow PHP's declare syntax: declare(line=17, file='hi'); // or declare(line=5) { // ... } Now concerning your use cases: It is fairly easy to rewrite PHP errors. One of the examples you give are Smarty templates. Twig (another template engine), already does line number rewrites by inserting `// line ...` comments into the template and extracting that information using the tokenizer. (https://github.com/fabpot/Twig/blob/master/lib/Twig/Error.php#L147) It's not terribly complicated. And this is the most complex case, where line number distribution is not just off-by-n, but really requires line-hints in the source. For the PHPT tests a simple addition of the number of lines before the actual test will suffice. Even no tokenizer needed. (Sorry, forgot to send to list)

Stas Malyshev

15 years ago
Hi! On 8/10/11 9:29 PM, Gwynne Raskind wrote:
> I've just created a new RFC, https://wiki.php.net/rfc/linecontrol , > regarding adding cpp(1)'s linemarkers to PHP. Discussion is invited. > > -- Gwynne >
Frankly, this seems to be pretty narrow use case for language syntax change. Though you could in theory run PHP through all kinds of preprocessors, including cpp, in practice this is rarely done, and one could as well write a short app which parses error messages and does necessary substitutions for these narrow cases.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227