|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-19 23:14 UTC] wez@php.net
[2004-09-18 22:02 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Feb 10 03:00:01 2026 UTC |
Description: ------------ [code] function array_finalize(&$context) { if (isset($context)) { return $context; } return array(); } [/code] see reproduce code for full snip. This is part of an sqlite_create_aggregate(). seems perfectly legal, but the array_finalize(&$context) can't return an array. A returned array from sqlite_fetch_array() will explicitly hold a NULL value instead of our array from our custom function. If you can't return an array, please tell so in the manual, if you are supposed to be able to return an array, please fix this. changing the finalize code into: [code] function array_finalize(&$context) { if (isset($context)) { return serialize($context); } return serialize(array()); } [/code] does work perfectly (if you use unserialize on the other end of-course...) Reproduce code: --------------- function array_step(&$context, $element) { if (!is_array($context)) $context = array(); if (isset($element)) { $e = sqlite_udf_decode_binary($element); if (!in_array($e, $context)) { // UNIQUE $context[] = $e; } } } function array_finalize(&$context) { if (isset($context)) { return $context; } return array(); } sqlite_create_aggregate($db, 'ARRAY', 'array_step', 'array_finalize'); $q = "SELECT name, ARRAY(friends) as friends FROM friends GROUP BY name"; // just an example of a friends table (name,friendsname) $r = sqlite_query($db, $q); while ($a = sqlite_fetch_array($r, SQLITE_ASSOC)) { foreach($a['friends'] as $friend) tellFriend($friend); // whatever } Expected result: ---------------- tellFriends gets executed per friend of one person. Then we while up to the next result and tellFriends gets executed per friend of the next person ... etc etc Actual result: -------------- $a['friends']=NULL (explicitly set to NULL)