php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45111 Support of #line instruction for parser context substitutuon
Submitted: 2008-05-27 22:54 UTC Modified: 2010-12-22 13:45 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at koterov dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.6 OS: all
Private report: No CVE-ID: None
 [2008-05-27 22:54 UTC] php at koterov dot ru
Description:
------------
In Perl, we could write the following program test.pl (lines are enumerated for better look):

01  #!/usr/bin/perl -w
02  print "hello!\n";
03  print "something!\n";
04
05  #line 100 "aaa.pl"
06  print $undefined_var;

This code generates a warning message "Using of undefined variable", but (attention!) - the context of this error is NOT "test.pl line 5", but - "aaa.pl line 100".

So, the "pseudo-comment" operator

#line xxx "yyy"

in Perl substitutes the current parsing context to a specified line number and filename. (You may ommit filename, then - only the line number will be substituted). And, if a warning or a fatal error occurs, the line number and filename in the error message will be changed. There is the same feature in C language: it is used by C preprocessor to execute #include directives an keep line numbers clear to understand.

This feature is VERY VERY useful when we write some code translator (e.g. from a templating language to pure PHP). This kind of translation is done e.g. in Smarty: it translates Smarty templates into pure PHP code, but line numbers are mixed up in translated files, so we cannot revert back and detect which line of the template had produced an error.

Please say, do you plan to add this feature to a new PHP versions? I'd like to ask you very much about it...



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-12 21:24 UTC] php at koterov dot ru
I have dug the PHP source code a little.

Hmm, seems this feature is not too easy to implement...

Line number is stored in znode, it's easy to substitute. But filename is stored in zend_op_array, NOT in zend_op. So, for a sequence of opcodes grouped by a single zend_op_array there is no chance to specify different filenames. (Of course I could add a field to zend_op, but in this case all accelerators like eAccelerator seem to stop working, because they know nothing about this field and do not store/restore it.)

Am I right?
 [2010-12-22 13:45 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-12-22 13:45 UTC] johannes@php.net
See #32734.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 21 08:00:02 2025 UTC