php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28643 __LINE__ miscounts in case of using \r or \n as a newline
Submitted: 2004-06-05 16:06 UTC Modified: 2004-06-06 05:27 UTC
From: key at kemcity dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: possibly any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: key at kemcity dot ru
New email:
PHP Version: OS:

 

 [2004-06-05 16:06 UTC] key at kemcity dot ru
Description:
------------
While debugging and getting some error I receive the error in wrong line number. I suppose strict errors, not like a missing bracket or something like that. For example unknown method, variable and something like that. So, line number can be defined surely. After than I've played with  __LINE__ and I've got a result. It reported some strange number of line. I suppose it's linked to CR, LF: i can reproduce this bug hard ;) So, the url is included in bugreport. Good luck. I had this bug before and find it very annoying. Some replics of others in the Internet doesn't answer at all.
P.S. Script doesn't have a # sign at the top.

Reproduce code:
---------------
The page with links to 2 tests and 2 source codes:
 http://key.users.kemcity.ru/

Direct Links
 Test1:
  http://key.users.kemcity.ru/index1.php
 Test2:
  http://key.users.kemcity.ru/index2.php

Source Code
 Source1:
  http://key.users.kemcity.ru/index1.txt
 Source2:
  http://key.users.kemcity.ru/index2.txt


Expected result:
----------------
Test1:
Does 10=10? [/www/htdocs/users/homepage/key/index1.php]
Test2:
Does 7=7? [/www/htdocs/users/homepage/key/index2.php]


Actual result:
--------------
Test1:
Does 4=10? [/www/htdocs/users/homepage/key/index1.php]
Test2:
Does 4=7? [/www/htdocs/users/homepage/key/index2.php]


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-05 16:24 UTC] derick@php.net
The URLs you provided don't work (can't be resolved). 
 [2004-06-05 16:33 UTC] key at kemcity dot ru
And I found, that when I change the $0d symbol with $0a symbol, __LINES__ corrected. Replace inside of constructions like arrays [even big ones] doesn't do anything.
The only problem is that my editor (FaR manager) uses $0d and $0a in mixed order [i suppose exactly as previous newline], notepad uses $0d$0a strictly. As far as I know, unix editor use the one symbol for newline.
Is this a solution? To use only an $0d$0a for newline?
 [2004-06-05 16:35 UTC] derick@php.net
No, you just need to use ONE style of line endings, this is not a bug and thus we mark it as bogus.
 [2004-06-05 16:44 UTC] key at kemcity dot ru
ok. I'll try,. Thanks for solution. It was a pleasure to get the answer so soon. ;) And anyway I can't understand why I can't use the deffierent kind of newline symbol ;)))
 [2004-06-05 16:52 UTC] key at kemcity dot ru
I've changed all newlines in file to $0d. There is no any $0a in file. Is this a solution? Error still out. Check the 
http://soft.kemcity.ru/test/index3.php and http://soft.kemcity.ru/test/index3.txt (source)
 [2004-06-05 16:54 UTC] key at kemcity dot ru
Only after changing any $0d to $0d$0a I've got right result. So, the right definition is: use only $0d$0a in your scripts to get right __LINE__ count. Am I right?
 [2004-06-05 16:55 UTC] key at kemcity dot ru
not any but every.

Excuse me for a lot of msgs.
 [2004-06-05 18:13 UTC] key at kemcity dot ru
For my followers: 
to change the script appropriate the requirements, you should replace any occurence of "wrong" newline. I used the next simple script:

  $filenameIn="funct.php";
  $filenameOut="funct.out.php";
  $x=fopen($filenameIn,"r");
  $buf=fread($x,filesize($filenameIn));
  fclose($x);
  $buf=preg_replace("/\r([^\n])/si","\r\n$1",$buf);
  $buf=preg_replace("/([^\r])\n/si","$1\r\n",$buf);
  $x=fopen($filenameOut,"w+");
  fwrite($x,$buf);
  fclose($x);
 [2004-06-06 05:27 UTC] key at kemcity dot ru
I suppose, nobody helps me ;) I hope others are awared of this bug and would find it at google, for example. Because I couldn't.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 10:01:34 2025 UTC