php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25781 strpos doesn't know if the file passed EOF
Submitted: 2003-10-07 15:02 UTC Modified: 2003-10-07 15:46 UTC
From: imscorpio at hotmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.3 OS: Windows 2000 Pro
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: imscorpio at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-10-07 15:02 UTC] imscorpio at hotmail dot com
Description:
------------
If you loop a file line by line and searching with strpos() it doesn't know if the file has ended, reached EOF. It will contiue untill crash...

Reproduce code:
---------------
//scritp.php
<?php
	$my_position = int;
	$haystack = $file_line[$my_position];
	$position = strpos ( $haystack, $needle );
	while ($position === false){
		$my_position++;
		$haystack = $file_line[$my_position];
		$position = strpos ( $haystack, $needle );
	}
?>

Expected result:
----------------
Nothing to read from or the $haystack has passed the EOF.

Actual result:
--------------
Fatal error: Maximum execution time of 30 seconds exceeded in script.php on line 9
Any line within the while()
during 30sec it can go up to 65.000 - 70.000 lines

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-07 15:46 UTC] jay@php.net
"$my_position = int;" probably isn't doing what you're 
expecting it to do. It's setting $my_position to the 
string "int", not making it an integer. (Use a var_dump() 
and you'll see what I'm talking about.) 
 
A for loop or a foreach loop would probably be better in 
this case anyway, breaking out of it if necessary when 
strpos() returns false. 
 
J 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 23:01:27 2024 UTC