|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20035 __LINE__ miscounts with #!/path/php scripts
Submitted: 2002-10-22 19:34 UTC Modified: 2002-11-05 16:07 UTC
From: befletch at yahoo dot com Assigned: iliaa (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4.2.3 OS: OpenBSD 3.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: befletch at yahoo dot com
New email:
PHP Version: OS:


 [2002-10-22 19:34 UTC] befletch at yahoo dot 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
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-22 19:39 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2002-10-22 20:25 UTC] befletch at yahoo dot 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:

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-23 00:44 UTC]
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.

 [2002-10-23 10:13 UTC]
The shebang line doesn't get stripped off by the kernel, PHP does that. This is a bug.
 [2002-11-05 16:07 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Aug 09 08:05:44 2022 UTC