[pmwiki-users] Irreproducible behavior - maybe a bug

Joachim Durchholz jo at durchholz.org
Tue May 10 16:07:55 CDT 2005


Hi all,

I'm despairing over getting a markup to work. Depending on whether 
preg_replace was called before or not, Markup() will enter an endless 
recursion.

This works:

Markup(
'mailform2-To',
'>links',
'/\\(:mailform2\sTo:\\)/i',
'<input size="" value="" style="">');

This does not:

   $text = '';
   $size = '';
   $attrs = '';
   $field = 'To';
   $MailForm2[$field . 'Text']
     = '<input size="$size" value="$text"$attrs>';
   $replacement =
     preg_replace(
       array('/\\$text/', '/\\$size/', '/\\$attrs/'),
       array(htmlentities($MailForm2[$field . 'Text']), $size, $attrs),
       $html
     );
   Markup(
     "mailform2-$field",
     '>links',
     '/\\(:mailform2\\s' . $field . ':\\)/i',
     $replacement);

I have traced it down to Markup(), where it says
       foreach((array)@$MarkupTable[$id]['dep'] as $i=>$m)
         Markup($i,"$m$id");
Most of the time, if $MarkupTable[$id]['dep'] isn't defined, the (array) 
it will create an empty array just alright, but after calling 
preg_replace(), this generates
   array (0 => '')
and when iterating that array in the foreach loop, it will look like
   array ('' => 'mailform2-To')

I'm using PHP 4.1.2.

----

On a tangent: if somebody knows a better way to first define a string as
   'bla $var blub'
and, later, have $var substituted in it, I'd be grateful. That 
preg_replace thing is rather unwieldy anyway. (I have considered eval(), 
but it seems to defeat the purpose of precompilation so I'm a bit 
cautious about it.)

Regards,
Jo



More information about the pmwiki-users mailing list