diff --git a/ext/pdo/tests/pdo_fetch_class_opaque_object.phpt b/ext/pdo/tests/pdo_fetch_class_opaque_object.phpt new file mode 100644 index 0000000000000..eaef3f6e8f353 --- /dev/null +++ b/ext/pdo/tests/pdo_fetch_class_opaque_object.phpt @@ -0,0 +1,57 @@ +--TEST-- +PDO Common: Attempting to initialize an opaque object via PDO::FETCH_CLASS +--EXTENSIONS-- +pdo +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE pdo_fetch_class_opaque_object(id int NOT NULL PRIMARY KEY, path VARCHAR(10))'); +$db->exec("INSERT INTO pdo_fetch_class_opaque_object VALUES(1, 'AA')"); +$db->exec("INSERT INTO pdo_fetch_class_opaque_object VALUES(2, 'BB')"); +$db->exec("INSERT INTO pdo_fetch_class_opaque_object VALUES(3, 'CC')"); + +$stmt = $db->prepare('SELECT path FROM pdo_fetch_class_opaque_object'); +$stmt->execute(); + +var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'Directory', [])); +?> +--CLEAN-- + +--EXPECTF-- +array(3) { + [0]=> + object(Directory)#%s (1) { + ["path"]=> + string(2) "AA" + ["handle"]=> + uninitialized(mixed) + } + [1]=> + object(Directory)#%s (1) { + ["path"]=> + string(2) "BB" + ["handle"]=> + uninitialized(mixed) + } + [2]=> + object(Directory)#%s (1) { + ["path"]=> + string(2) "CC" + ["handle"]=> + uninitialized(mixed) + } +} diff --git a/ext/pdo/tests/pdo_fetch_function_exception_in_call.phpt b/ext/pdo/tests/pdo_fetch_function_exception_in_call.phpt new file mode 100644 index 0000000000000..7afeaf971a3df --- /dev/null +++ b/ext/pdo/tests/pdo_fetch_function_exception_in_call.phpt @@ -0,0 +1,55 @@ +--TEST-- +PDO Common: PDO::FETCH_FUNC with a call that throws an exception for one specific value +--EXTENSIONS-- +pdo +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE pdo_fetch_function_exception_in_call(id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10))'); +$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(1, 'A', 'alpha')"); +$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(2, 'B', 'beta')"); +$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(3, 'C', 'gamma')"); +$db->exec("INSERT INTO pdo_fetch_function_exception_in_call VALUES(4, 'D', 'delta')"); + +$selectVals = $db->prepare('SELECT val1, val2 FROM pdo_fetch_function_exception_in_call'); + +function bogusCallback(string $val1, string $val2) { + $r = $val1 . ': ' . $val2 . PHP_EOL; + echo $r; + if ($val2 === 'gamma') { + throw new Exception("GAMMA IS BAD"); + } + return $val1 . ': ' . $val2; +} + +$selectVals->execute(); + +try { + $result = $selectVals->fetchAll(PDO::FETCH_FUNC, 'bogusCallback'); + var_dump($result); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--CLEAN-- + +--EXPECT-- +A: alpha +B: beta +C: gamma +Exception: GAMMA IS BAD