From 8a81d005e53bcfac700c0760aa99afba65ab563d Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 26 Jan 2025 03:33:38 +0000 Subject: [PATCH] ext/pdo: Add a test creating instances of Directory This should not be possible, other opaque classes cannot be instantiated in practice as they do not have properties and prevent dynamic properties --- .../tests/pdo_fetch_class_opaque_object.phpt | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ext/pdo/tests/pdo_fetch_class_opaque_object.phpt 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 00000000000..eaef3f6e8f3 --- /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) + } +}