From: ozy at ozy dot student dot utwente dot nl
Operating system: Mac OS X
PHP version: 5.0.0
PHP Bug Type: SQLite related
Bug description: sqlite_create_aggregate() can't return any php type
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)
--
Edit bug report at http://bugs.php.net/?id=29266&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29266&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29266&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29266&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29266&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29266&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29266&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29266&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29266&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29266&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29266&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29266&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29266&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29266&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29266&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29266&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29266&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29266&r=float