KBD

Keith Devens .com

Friday, July 4, 2008 Flag waving
That which yields, is not always weak. – Jacqueline Carey (Kushiel's Dart)

Archive: March 07, 2005

← March 06, 2005March 08, 2005 →

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?

← March 06, 2005March 08, 2005 →
July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



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

Recent comments XML

Girls, please don't get breast implants

> And no, you will not be receiving​a picture.

:-(...

Keith: Jul 2, 6:05am

Javascript clone function

This is a clever way to clone an​object if you are using YAHOO UI.​Same tec...

Antonio: Jul 1, 12:47pm

I hate Norton Antivirus

Oh just one other thing norton is​great at keeping people out of your​compu...

kevin.sands: Jul 1, 12:50am

Terminator 3 was awful

I think the biggest reason why T3​totally blew was because Edward​Furlong g...

76.167.172.64: Jun 29, 3:06am

Generated in about 0.051s.

(Used 7 db queries)

mobile phone