[pmwiki-users] Irreproducible behavior - maybe a bug

Joachim Durchholz jo at durchholz.org
Thu May 12 05:46:54 CDT 2005


Joachim Durchholz wrote:
> Patrick R. Michaud wrote:
> 
>> On Wed, May 11, 2005 at 10:27:10PM +0200, Joachim Durchholz wrote:
>>
>>> Oh, and looking on http://www.php.net/language.types.type-juggling I 
>>> found this:
>>> "Note:  The behaviour of an automatic conversion to array is 
>>> currently undefined."
>>> In the light of this remark, I find the stability of PmWiki 
>>> remarkable - after all, there are 64 occurrences of (array) in the 
>>> PmWiki code. Seems like the conversion isn't *that* undefined, just 
>>> long-standingly buggy and nobody ever cared to fix it...
>>
>>
>> Well, except that this isn't an example of an automatic conversion
>> to an array.  Because of the (array) in front, it's *not* automatic,
>> it's a type cast, and typecasting is very well defined -- see
>> http://us3.php.net/manual/en/language.types.array.php#language.types.array.casting 
>>
> 
> 
> Ah, right.
> 
> Then it's probably just a bug in PHP :-/
> 
>> An "automatic conversion" would be where someone sends a
>> non-array value to a function or operator that can only work
>> on arrays, but doesn't use a cast.
> 
> 
> Strange if automatic conversion would be a problem and explicit one 
> wouldn't... but well.
> 
>> I'm thinking it must be something in the code other than
>> the (array) itself that is causing the problem.  It might be
>> an operator precedence issue -- try changing the line to read:
>>
>>       foreach((array)(@$MarkupTable[$id]['dep']) as $i=>$m)
>>
>> and see if that resolves the problem or gives a useful
>> error message.  It would explain a lot.
> 
> 
> No, that doesn't help.
> 
> I'll see whether I can come up with something else.

OK - one thing worked for me: using

   $replacement =
     str_replace(
       array('$text', '$size', '$attrs'),
       array($text, $size, $attrs),
       $html
     );

instead of

   $replacement =
     preg_replace(
       array('/\\$text/', '/\\$size/', '/\\$attrs/'),
       array($text, $size, $attrs),
       $html
     );

did the trick for me. Cleaner code anyway.

I'm not sure what to do about the situation in general. Squashing this 
bug by removing one of its triggers (those (array) type conversions) 
would make me sleep better, this doesn't prevent other bugs in 4.1.2 
from surfacing. Replacing (array)something with to_array(something) 
might improve the PmWiki code (it would certainly get rid of precedence 
bugs, once and for all), but it might gain only marginally more stability.
I'd love to upgrade to a more recent version of PHP, but that's not an 
option for me. My server is running without a firewall, so I'm forced to 
a Linux distribution that has a working security team and automatic 
security patch installation, and Debian woody was the one that had this 
- there's hope that Debian will switch to a faster release cycle once 
they have their current next release done, but that will take months to 
happen. So short of switching to an entirely different distro, I'm stuck 
with PHP 4.1.2 :-( ... I *could* try and install a recent version of PHP 
from source, but (1) that's a nontrivial task that doubtlessly would 
take more time that I'd like to spend, and (2) I'd have to manually 
follow security advisories to keep that PHP secure, which is more work 
than I can shoulder.
All that said, I'm (reluctantly) stuck with recommending to replace the 
(array) conversions with to_array() calls... :-(

Regards,
an unhappy Jo



More information about the pmwiki-users mailing list