PHP 4.0 Bug #6740: * sometimes doesn't work like expected (doesn't match 0 characters)

From: Date: Wed, 13 Sep 2000 22:54:13 +0000
Subject: PHP 4.0 Bug #6740: * sometimes doesn't work like expected (doesn't match 0 characters)
Groups: php.dev 
Request: Send a blank email to php-dev+get-33231@lists.php.net to get a copy of this message
From: thow@gmx.net Operating system: Linux 2.2.14 PHP version: 4.0.2 PHP Bug Type: PCRE related Bug description: * sometimes doesn't work like expected (doesn't match 0 characters) SCRIPTS: ===== regexp.pl (works like expected): ====== #!/usr/bin/perl -w sub process_hashmark { my $s = shift @_; if ($s eq '') { print "Matched string: empty string\n"; } else { print "Matched string: $s\n"; } return 'XX' if ($s eq ''); return 'ZZZ'; } my $s; my $regexp = 'X([^X]*?)X'; if (defined $ARGV[0]) { $s = $ARGV[0]; } else { $s = 'abcXdefXghi'; } print "Regular Expression: $regexp\n"; print "String to process: $s\n"; $s =~ s/$regexp/process_hashmark($1)/ge; print "Processed String: $s\n"; ===== regexp.pl (end) regexp.php (works not like expected): ===== function process_hashmark($string) { if ($string == "") { print "Matched string: empty string<br>\n"; } else { print "Matched string: $string<br>\n"; } if ($string == "") return "XX"; return "ZZZ"; } $regexp = "X([^X]*?)X"; if (empty($s)) $s = "abcXdefXghi"; echo "Regular Expression: $regexp<br>\n"; echo "String to process: $s<br>\n"; $s = preg_replace("/$regexp/e", "process_hashmark(\\1);", $s); echo "Processed string: $s<br>\n"; ===== regexp.php (end) OUTPUT: ===== regexp.pl (case 1): Regular Expression: X([^X]*?)X String to process: abcXdefXghi Matched string: def Processed String: abcZZZghi regexp.pl (case 2): Regular Expression: X([^X]*?)X String to process: abcXXdefXghi Matched string: empty string Processed String: abcXXdefXghi regexp.php (case 1): Regular Expression: X([^X]*?)X String to process: abcXdefXghi Matched string: def Processed string: abcZZZghi regexp.php (case 2): Regular Expression: X([^X]*?)X String to process: abcXXdefXghi Matched string: XdefXghi Processed string: abcZZZdefXghi CONFIGURE LINE: ===== ./configure --with-apxs --with-pgsql=/usr/lib/pgsql --with-mysql=/usr php.ini should be irrelevant and there is nothing special in our setup

« previous php.dev (#33231) next »