From: f_nietsje at hotmail dot com
Operating system: Win NT
PHP version: 5.0.1
PHP Bug Type: Scripting Engine problem
Bug description: globals not available in functions called from preg_replace_callback
Description:
------------
I use preg_replace_callback to substitute parts of an expression with
either true or false after which the expression can be evaluated using
eval:
_q1,1,1-2 & _q2,3-4,7
should become
true & false
which can be evaluated to false.
The strings represent answers to questions (it's for an interview system)
The problem is that the answers are stored in a global array. The (global)
array can not be read from a function that is called from
preg_replace_callback
It would be nice if somebody can fix this :-)
Reproduce code:
---------------
function parseqstring($qstring)
{
global $qre;
preg_match_all('/(\d+-\d+|\d+)/', $qstring, $numbers);
$q = array_shift($numbers[0]);
foreach($numbers[0] as $number)
{
//if its a number check the answer
if(is_numeric($number))
{
//if the answer is there return true because it's all 'or'
conditions
if($qre[$q]['answers'][$number]==1)
{
return 'true';
}
}
//if its a range check all the numbers in the range
if(preg_match('/(\d+)-(\d+)/', $number, $match))
{
for($i=$match[1];$i<=$match[2];$i++)
{
if($qre[$q]['answers'][$i])
{
return 'true';
}
}
}
}
return 'false';
}
Expected result:
----------------
input:
$qstring = _q1,1,3-4
$qre[1]['answers'][3]
output:
'true'
Actual result:
--------------
'false'
--
Edit bug report at http://bugs.php.net/?id=30341&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30341&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30341&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30341&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30341&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30341&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30341&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30341&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30341&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30341&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30341&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30341&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30341&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30341&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30341&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30341&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30341&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30341&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30341&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30341&r=mysqlcfg