Re: Re: #20035 [Asn->Opn]: __LINE__ miscounts with #!/path/php scripts

From: Date: Thu, 24 Oct 2002 06:58:55 +0000
Subject: Re: Re: #20035 [Asn->Opn]: __LINE__ miscounts with #!/path/php scripts
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-90042@lists.php.net to get a copy of this message
hi, (Zeev and Andi, and other core devlopers are surely familiar with this, but maybe I can help, too) the cause of this problem is something like this: (1) in sapi/cgi/cgi_main.c(1118) or sapi/cli/php_cli.c(643), if the very begginig of the script is '#', PHP strips that line. at that time, CG(zend_lineno) is surely incremented. but after that... (2) in open_file_for_scanning() in Zend/zend_language_scanner.l (main() -> php_execute_scripts() -> zend_execute_scripts() -> zend_compile_file() -> open_file_for_scannning()), CG(zend_lineno) is reset to 1. so... uhm, fixing this is not so easy, I think. if PHP does not strip first line, PHP just prints that line, because that line should outside of the script. maybe we need some kind of a flag in CG, but it'll be an ugly hack. hmm, any idea? or leave this as the "PHP spec"? :) Masaki Fujimoto <fujimoto@php.net> On Thu, 24 Oct 2002 09:18:04 +0300 (EEST) Jani Taskinen <sniper@iki.fi> wrote: > > Er...You propably know then where this stripping happens > in PHP or Zend ?? (I couldn't find it..) > > --Jani > > > > On 23 Oct 2002 sander@php.net wrote: > > > ID: 20035 > > Updated by: sander@php.net > > Reported By: befletch@yahoo.com > >-Status: Assigned > >+Status: Open > >-Bug Type: Documentation problem > >+Bug Type: Scripting Engine problem > > Operating System: OpenBSD 3.1 > > PHP Version: 4.2.3 > > Assigned To: hholzgra > > New Comment: > > > >The shebang line doesn't get stripped off by the kernel, PHP does that. > >This is a bug. > > > > > >Previous Comments: > >------------------------------------------------------------------------ > > > >[2002-10-23 00:44:20] derick@php.net > > > >Your kernel strips the first line, and so PHP sees the last 3 lines. As > >it doesn't know that the kernel stripped the first shebang line it's > >obvious that your line 3 reports line 2. > > > >Derick > > > >------------------------------------------------------------------------ > > > >[2002-10-22 20:25:37] befletch@yahoo.com > > > >Excuse me, but I don't understand why this isn't a bug. The only > >reference to __LINE__ I can find in the documentation is here: > > > >http://www.php.net/manual/en/language.constants.php > > > >I can find nothing that suggests it is reasonable that __LINE__ counts > >are off by one when used in #! prefixed command line scripts, (but not > >in other uses) and I can see no reason why this would be considered > >reasonable behaviour. > > > >Can someone give me at least a 1 sentence explanation instead of just > >hitting the 'quick-fix' RTFM button? > > > >------------------------------------------------------------------------ > > > >[2002-10-22 19:39:04] iliaa@php.net > > > >Thank you for taking the time to write to us, but this is not > >a bug. Please double-check the documentation available at > >http://www.php.net/manual/ and the instructions on how to > >report > >a bug at http://bugs.php.net/how-to-report.php > > > > > > > >------------------------------------------------------------------------ > > > >[2002-10-22 19:34:54] befletch@yahoo.com > > > >The built-in variable __LINE__ undercounts by 1 on command-line scripts > >that begin with a #!path-to-php line. For example: > > > >#!/usr/local/bin/php -q > ><?php > >echo "Line 3 reports ".__LINE__."\n"; > >?> > > > >This script will output: > > > >Line 3 reports 2 > > > >This issue also applies to (at least) some other 4.1+ releases. > > > > > >------------------------------------------------------------------------ > > > > > > > > -- > <- For Sale! -> > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.dev (#90042) next »