#39882 [NEW]: no array being returned from function

From: Date: Tue, 19 Dec 2006 12:14:32 +0000
Subject: #39882 [NEW]: no array being returned from function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-106553@lists.php.net to get a copy of this message
From: testuser at phpizabi dot net Operating system: CENT OS 4.4 i686 PHP version: 4.4.4 PHP Bug Type: Arrays related Bug description: no array being returned from function Description: ------------ It seems that I am not being able to return an array from a function. I read a serialized string, unserialize it and then call a recursive function to get the deepest keys and values Reproduce code: --------------- $test_serial = <<< FO a:5:{i:0;a:7:{s:8:"question";s:31:"What is your tv watching habits";s:5:"field";s:10:"checkboxes";s:7:"default";N;s:9:"charwidth";N;s:5:"lines";N;s:6:"maxlen";N;s:7:"options";s:54:"never watch tv |always am on the tube |i dont own a tv";}i:1;a:7:{s:8:"question";s:27:"What is your favorite genre";s:5:"field";s:12:"radiobuttons";s:7:"default";N;s:9:"charwidth";N;s:5:"lines";N;s:6:"maxlen";N;s:7:"options";s:19:"horror |sex |comedy";}i:2;a:7:{s:8:"question";s:0:"";s:5:"field";s:9:"textfield";s:7:"default";s:6:"sfasdf";s:9:"charwidth";s:8:"sadfasdf";s:5:"lines";N;s:6:"maxlen";s:7:"asdfasd";s:7:"options";N;}i:3;a:7:{s:8:"question";s:27:"what is your favorite color";s:5:"field";s:9:"textfield";s:7:"default";s:0:"";s:9:"charwidth";s:0:"";s:5:"lines";N;s:6:"maxlen";s:0:"";s:7:"options";N;}i:4;a:7:{s:8:"question";s:14:"favorte things";s:5:"field";s:9:"textfield";s:7:"default";s:0:"";s:9:"charwidth";s:0:"";s:5:"lines";N;s:6:"maxlen";s:0:"";s:7:"options";N;}} FO; $test = unserialize($test_serial); $test_keys = array(); $test_val = array(); function getarr_items($array,$mode){ $newarray = array(); if(is_array($array)){ foreach($array as $key => $val){ if(is_array($val)){ getarr_items($val,$mode); } else { if($mode == "k"){ $newarray[] = $key; } else $newarray[] = $val; } } } return $newarray; } $test_keys = getarr_items($test,'k'); $test_val = getarr_items($test,'v'); print_r($test_keys); echo "<------>"; print_r($test_val); Expected result: ---------------- should return an array with values Actual result: -------------- empty array -- Edit bug report at http://bugs.php.net/?id=39882&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39882&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39882&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39882&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39882&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39882&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39882&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39882&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39882&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39882&r=support Expected behavior: http://bugs.php.net/fix.php?id=39882&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39882&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39882&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39882&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39882&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39882&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39882&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39882&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39882&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39882&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39882&r=mysqlcfg

« previous php.bugs (#106553) next »