KBD

Keith Devens .com

Sunday, March 21, 2010 Flag waving
Couldn't get random quote: Got error 28 from storage engine – MySQL
← 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)
:

March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



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

Recent comments XML

new⇒Spider solitaire

I to am somewhat addicted to​spending too much time on SS.  I​have been stu...

stupid_horse: Mar 20, 10:34pm

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.116s.

(Used 8 db queries)