KBD

Keith Devens .com

Monday, October 13, 2008 Flag waving
No battle plan ever survives contact with the enemy. – Field Marshall Helmuth Carl Bernard von Moltke
← Syria and WMDCrazy animal tricks →

Daily link icon Monday, March 7, 2005

PHP 5 bug in array_walk?

The following code works differently in PHP 4 and PHP 5.

<?php
array_walk
($tagmarkscreate_function('&$a',
'if(isset($a[\'tag_array\'])){
   array_walk($a[\'tag_array\'],\'resolveTitle\');
   sortTags($a[\'tag_array\']);
}'
));
?>

Here's resolveTitle and sortTags:

<?php
function resolveTitle(&$tag){ #used for callbacks
    
$tag['title'] = formatTitle($tag);
}
function 
sortTags(&$tags){
    
usort($tags'compareTags');
}
function 
compareTags($a,$b){
    
#accounts for if the titles are the same, and then sorts by tag
    
return $a['title'] == $b['title'] ?
        
strcmp($a['tag'],$b['tag']) :
        
strnatcasecmp($a['title'],$b['title']);
}
?>

(Some code reformatted to wrap.) In PHP 5, the code only handles the first instance of a 'tag_array', whereas on 4 it does what it should. AFAICT this code isn't hitting any known problem areas of PHP 5 (such as object references), so, without doing more analysis, the only thing I can blame the difference on is a bug in PHP 5. Maybe the array_walk nesting does it?

I'm sticking this here largely because I'm going to change the code to make it work in PHP 5, and I want a record of it. I don't have time now to A) go through the PHP CVS looking for changes that would cause this B) play with this to isolate what's broken. Anyone have any idea what's making this code break?

← Syria and WMDCrazy animal tricks →

Comments XML gif


Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

October 2008
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 7 posts

Recent comments XML

new⇒Spider solitaire

I have now won, at the "Difficult"​level, 186 games of Spider​Solitaire.  I...

75.179.28.113: Oct 13, 9:34am

new⇒Girls, please don't get breast implants

Please, don't marry him.

You​want to get surgery to make​yourself more i...

gigi: Oct 12, 11:47pm

I hate PHP

Elliot Anderson,

Dude!! You the​man! The reverse replacement for​array_u...

Alex Ndungu: Oct 11, 1:35am

Call a function from a string in Python

?!code:
some_object.__getattribute​__('method_name')()
?!/code

is​the s...

Patrick Corcoran: Oct 8, 3:53pm

Sed one-liners

Hi.

I wanted to let you know​that I wrote an article "Famous Sed​One-Lin...

Peteris Krumins: Oct 8, 3:05am

Timesheet Calculator

Hadn't seen it before now, but my​company already uses a time​tracking prog...

Keith: Oct 7, 10:44am

Generated in about 0.189s.

(Used 8 db queries)

mobile phone