php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37662 "Call to undefined function ()" when with strpos("\r")
Submitted: 2006-06-01 08:29 UTC Modified: 2006-06-01 09:39 UTC
From: mg at evolution515 dot net Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.1.4 OS: Debian/Sarge
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mg at evolution515 dot net
New email:
PHP Version: OS:

 

 [2006-06-01 08:29 UTC] mg at evolution515 dot net
Description:
------------
Search for the comment "try changing this value!" und try one run with "\r" (BAD!) and then another with "\n" or "\t" (BOTH GOOD).

RESULT:
While the first run of strpos() is successful, the other one in the while-loop results in an error!

OUTPUT: 
strpos() has been successfuly run
Fatal error: Call to undefined function  () in /home/www/Projekte/flyerpilot.de/htdocs.dev/MimeMagic/BUG.php on line 41

NOTE:
I encounter often errors especially in sentences like 
"if ($a ||$b) " that results in the same error. The only workaround I found so far is"if ($a+$b>0)" that usualy works good. 

Do you know about this error? I couldn't find any related ticket. And I really get it for some PHP versions back.

Oh yeah.. i was to lazy to recompile, but i guess that error will still exist in 5.1.4 as it did since 5.0 or before.

PHP Version 5.1.2-Debian-0.1~sarge1 (Debian GNU/Linux)

Reproduce code:
---------------
<?php

// User your linux /usr/share/misc/magic for the magic-file!

class MagicReader {
	
	private $magicBuffer = '';
	private $magicFile;
	
	private $fp;
	
	
	function __construct($filename=null) {
		if (is_string($filename))
			$this->openMagicFile($filename);
		$this->convert();	
		$this->closeMagicFile();
	}
	
	
	function openMagicFile($filename) 	{
		$this->magicFile = @fopen($filename, 'r');
		return $this->magicFile;
	}
	
	
	function closeMagicFile() 	{
		return @fclose($this->magicFile);
	}
	
	
	function convert() {
		while ($line = $this->readLine()) {
			echo $line;
			die();
		}
	}
	
	
	private function readLine() 
	{
		
		while ((!@feof($this->magicFile)) || (strlen($this->magicBuffer)>0)) {	
			$lfPos = strpos($this->magicBuffer, "\n"); // cahnge this value to R!
			if ($lfPos !==false) {
				$this->magicBuffer = substr($this->magicBuffer, $lfPos);
				return substr($this->magicBuffer, $lfPos)."|";
			}
			$this->magicBuffer = @fread($this->magicFile, 4096);
		}
		
		// if we reached this position we are at the end of the file!
		
		$out = $this->magicBuffer; // assign return output
		
		if (empty($this->magicBuffer)) {// if buffer is already empty we are really at the end
			return false;
		}
			
		$this->magicBuffer = ''; // clear out buffer
		
		return $out;	
	} 

	
	
	function __destruct() {
		$this->closeMagicFile();
	}
}

$str = "That's a\rlittle Test!";
echo (strpos($str, "\r")) ? "strpos() has been successfuly run!" : "nothing found but successfuly run!";

$reader = new MagicReader("magic");


?>

Expected result:
----------------
No error message.

Actual result:
--------------
Simple enough. Check out the source!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-01 08:36 UTC] tony2001@php.net
Works just fine here.
 [2006-06-01 08:37 UTC] mg at evolution515 dot net
Ok, and strpos() doesn't find any \n on the search string although there are surely \n in there.
I've just seen that was another bug. So this bug is surely realted, but please fix that "undefined function ()" in "if ($a || $b)" at last!!
 [2006-06-01 08:38 UTC] mg at memedia dot de
Have you replaced...

$lfPos = strpos($this->magicBuffer, "\n");

....with...

$lfPos = strpos($this->magicBuffer, "\r");

...?
 [2006-06-01 08:42 UTC] tony2001@php.net
# php /tmp/2.php
strpos() has been successfuly run!

I'm sure you don't need a class to check if strpos() finds '\r' or '\n' in strings.

 [2006-06-01 08:47 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.
 [2006-06-01 08:54 UTC] derick@php.net
Bug update collision, setting back to bogus.
 [2006-06-01 09:20 UTC] mg at evolution515 dot net
Ok, changed to PHP/5.1.4-1.dotdeb.1. Still the error.
CLI as libapache2 produce the same error.

$ php BUG.php 
strpos() has been successfuly run!
Fatal error: Call to undefined function  () in /home/www/Projekte/flyerpilot.de/htdocs.dev/MimeMagic/BUG.php on line 41

OK COPY AND PASTE FOLLWING SCRIPT AND TRY AGAIN!
--------------------------------------------------
<?php

class MagicReader {
	
	private $magicBuffer = '';
	private $magicFile;
	
	private $fp;
	
	
	function __construct($filename=null) {
		if (is_string($filename))
			$this->openMagicFile($filename);
		$this->convert();	
		$this->closeMagicFile();
	}
	
	
	function openMagicFile($filename) 	{
		$this->magicFile = @fopen($filename, 'r');
		return $this->magicFile;
	}
	
	
	function closeMagicFile() 	{
		return @fclose($this->magicFile);
	}
	
	
	function convert() {
		while ($line = $this->readLine()) {
			echo $line;
			die();
		}
	}
	
	
	private function readLine() 
	{
		
		while ((!@feof($this->magicFile)) || (strlen($this->magicBuffer)>0)) {	
			$lfPos = strpos($this->magicBuffer, "\r"); // cahnge this value to R!
			if ($lfPos !==false) {
				$this->magicBuffer = substr($this->magicBuffer, $lfPos);
				return substr($this->magicBuffer, $lfPos)."|";
			}
			$this->magicBuffer = @fread($this->magicFile, 4096);
		}
		
		// if we reached this position we are at the end of the file!
		
		$out = $this->magicBuffer; // assign return output
		
		if (empty($this->magicBuffer)) {// if buffer is already empty we are really at the end
			return false;
		}
			
		$this->magicBuffer = ''; // clear out buffer
		
		return $out;	
	} 

	
	
	function __destruct() {
		$this->closeMagicFile();
	}
}

$str = "That's a\rlittle Test!";
echo (strpos($str, "\r")) ? "strpos() has been successfuly run!" : "nothing found but successfuly run!";

$reader = new MagicReader("magic");


?>
 [2006-06-01 09:23 UTC] mg at evolution515 dot net
And copy /usr/share/misc/magic to your working dir so the script find a file! (Otherweise the script won't exit in with PHPCLI)
 [2006-06-01 09:39 UTC] tony2001@php.net
Works _perfectly fine_.
Please either provide a short reproduce script (do you really need those classes to read a file, eh?) or just debug your code yourself.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC