php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37167 PDO::FETCH_FUNC doesn't work with a callback
Submitted: 2006-04-22 15:30 UTC Modified: 2006-04-22 19:11 UTC
From: troelskn at gmail dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.2 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: troelskn at gmail dot com
New email:
PHP Version: OS:

 

 [2006-04-22 15:30 UTC] troelskn at gmail dot com
Description:
------------
Using PDO::FETCH_FUNC with fetchAll() only works with a function. It would be nice if it worked with a normal callback type (as in call_user_func and others).

If this can't be fixed, the error message must be changed, since "General error: user-supplied function must be a valid callback" is misleading.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-22 17:44 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-04-22 18:42 UTC] troelskn at gmail dot com
Reproduce code:
---------------
<?php
class Test
{
	protected $connection;

	function __construct() {
		$this->connection = new PDO("sqlite::memory:");
		$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		$this->connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
		$this->connection->query("CREATE TABLE test (a integer primary key)");
		$this->connection->query("INSERT INTO test VALUES (22)");
	}

	function select() {
		$query = "SELECT * FROM test";
		$result = $this->connection->query($query);
		return $result->fetchAll(PDO::FETCH_FUNC, Array($this, 'loadRecord'));
	}

	function loadRecord($row) {
		return new ArrayObject($row);
	}
}

$test = new Test();
var_dump($test->select());
?>

Expected result:
----------------
no error

Actual result:
--------------
Apache crashes.
 [2006-04-22 19:11 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 09 17:01:32 2024 UTC