php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36198 Not understandible ereg()-warning "Invalid preceding regular expression"
Submitted: 2006-01-29 12:37 UTC Modified: 2006-01-30 16:51 UTC
From: thomas at pixtur dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.1.2 OS: Debian Server
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thomas at pixtur dot de
New email:
PHP Version: OS:

 

 [2006-01-29 12:37 UTC] thomas at pixtur dot de
Description:
------------
The warning only occurs on very few plattforms. I probably could fix it in my code, if I could only understand it's meaning. If you google for the error-message you will find tons of broken pages with the same error but no explanation.




Reproduce code:
---------------
/* NOT reproducable */
class ListBlockColHtml extends ListBlockCol
{
	function render_tr(&$obj, $style="") {
		if(!isset($obj) || !is_object($obj)) {
			trigger_error("ListBlockColHtml->render_tr() called without valid object",E_USER_WARNING);
   			return;
		}
		$key= $this->key;
		$format= $this->format;
		$rest=$this->format;
		$style= $this->style
		      ? "class='$this->style'"
		      : '';

		while(	ereg("{\?([a-z_]*)}(.*)",$rest, $matches) ) { ### causes error
			$key=$matches[1];
	  		$rest=$matches[2];
			$value= isset($obj->$key) ? $obj->$key : "??$key";
			$format=ereg_replace("{\?$key}",$value,$format);
		}
		print "<td $style>$format</td>";
	}
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-29 12:39 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-01-29 13:08 UTC] thomas at pixtur dot de
As state in the report, I cannot personally reproduce the code. It was reported by a user (http://www.streber-pm.org/phpBB2/viewtopic.php?p=234#234). 

Since googling this message gives a lot of broken php-pages but not explanation what so ever, I posted this bug to "Documantation Problem". I need a explanation of what the error-message is trying to tell me, so I can adjust my code.

  tom
 [2006-01-30 15:42 UTC] vrana@php.net
\ is special character in PHP strings. If you want to match ?, write it as "\\?'.
 [2006-01-30 16:50 UTC] thomas at pixtur dot de
Thanks vrana@php.net. Good hint.

After trying a little bit I discoverd, that writing the regex as...

 ereg("\{\?([a-z_]*)\}(.*)",$rest, $matches)

... escapting the {} brackets fixes the problem. 

This also clarifies my problem: {} is the length parameter for the "preceding" match, which does not exists. So this was my fault. 
It's still strange that different PHP-installations behave differently...

  thanks for your help
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 02 08:01:32 2025 UTC