--TEST-- PDO Common: Testing PDO::FETCH_FUNC with various callables --EXTENSIONS-- pdo --SKIPIF-- --FILE-- exec('CREATE TABLE pdo_fetch_function_001(id int NOT NULL PRIMARY KEY, pl_name VARCHAR(10))'); $db->exec("INSERT INTO pdo_fetch_function_001 VALUES (1, 'php')"); $db->exec("INSERT INTO pdo_fetch_function_001 VALUES (2, 'sql')"); echo "Anonymous function:\n"; $st = $db->query('SELECT * FROM pdo_fetch_function_001'); $st->fetchAll( PDO::FETCH_FUNC, function($x, $y) { echo $x, ' ', $y, PHP_EOL; } ); echo "Internal function:\n"; $st = $db->query('SELECT pl_name FROM pdo_fetch_function_001'); var_dump($st->fetchAll(PDO::FETCH_FUNC, 'strtoupper')); echo "Relative class callable:\n"; class foo { public function method($x) { return __METHOD__ . "($x)"; } } class bar extends foo { public function __construct($db) { $st = $db->query('SELECT * FROM pdo_fetch_function_001'); var_dump($st->fetchAll(PDO::FETCH_FUNC, [$this, 'parent::method'])); } static public function factory($x, $y) { return __METHOD__ . "($x, $y)"; } } $bar = new bar($db); echo '["bar", "factory"] callable:', "\n"; $st = $db->query('SELECT * FROM pdo_fetch_function_001'); var_dump($st->fetchAll(PDO::FETCH_FUNC, ['bar', 'factory'])); echo '[$bar, "factory"] callable:', "\n"; $st = $db->query('SELECT * FROM pdo_fetch_function_001'); var_dump($st->fetchAll(PDO::FETCH_FUNC, [$bar, 'factory'])); echo '"bar::factory" callable:', "\n"; $st = $db->query('SELECT * FROM pdo_fetch_function_001'); var_dump($st->fetchAll(PDO::FETCH_FUNC, 'bar::factory')); ?> --CLEAN-- --EXPECTF-- Anonymous function: 1 php 2 sql Internal function: array(2) { [0]=> string(3) "PHP" [1]=> string(3) "SQL" } Relative class callable: Deprecated: Callables of the form ["bar", "parent::method"] are deprecated in %s on line %d array(2) { [0]=> string(14) "foo::method(1)" [1]=> string(14) "foo::method(2)" } ["bar", "factory"] callable: array(2) { [0]=> string(20) "bar::factory(1, php)" [1]=> string(20) "bar::factory(2, sql)" } [$bar, "factory"] callable: array(2) { [0]=> string(20) "bar::factory(1, php)" [1]=> string(20) "bar::factory(2, sql)" } "bar::factory" callable: array(2) { [0]=> string(20) "bar::factory(1, php)" [1]=> string(20) "bar::factory(2, sql)" }