[pmwiki-users] Irreproducible behavior - maybe a bug
Joachim Durchholz
jo at durchholz.org
Wed May 11 13:39:42 CDT 2005
Patrick R. Michaud wrote:
> On Tue, May 10, 2005 at 11:07:55PM +0200, Joachim Durchholz wrote:
>
>>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.
>
> Doesn't seem like preg_replace (by itself) would be the problem --
> there are quite a few times that preg_replace is called before Markup()
> is called.
Well, it's within config.php, so very little has happened yet.
What bothers me most is that I get a value that when var_dump()ed
displays as NULL, when (array)ed turns into an array(0, ''), and when
iterated with foreach turns into array(0, 'mailform2'). Something got
seriously unhinged within PHP itself.
> In your code...
>
>> $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);
>
> what is a typical value for $html?
Ah, one thing that I overlooked.
I'll try again with a less "cobwebby" mind (I was ill yesterday). I'll
investigate the issue below first though; if that doesn't help, I'll try
to give a better variable dump.
>>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.)
>
> Well, there's not a generic good way to do it, which is why I ended up
> creating FmtPageName to do this sort of thing. But beyond that,
> it's better to use str_replace over preg_replace for straight
> string replacements.
Ah, right. I was looking for str_replace but didn't find it.
> I also wonder about the preg_replace you have above -- given
>
>> $MailForm2[$field . 'Text']
>> = '<input size="$size" value="$text"$attrs>';
>> $replacement =
>> preg_replace(
>> array('/\\$text/', '/\\$size/', '/\\$attrs/'),
>> array(htmlentities($MailForm2[$field . 'Text']), $size, $attrs),
>> $html
>> );
>
> since '$text' is being replaced by $MailForm2[$field . 'Text'], and
> that value itself contains the string '$text' in it, I wonder if there
> might be some bizarre loop or occurrence there as well.
That's definitely a bug in the code.
And it's entirely conceivable that such a "loopy" replacements throws
preg_replace() off its track far enough that PHP gets into trouble.
I'll investigate further in that area.
Regards,
Jo
More information about the pmwiki-users
mailing list