]> granicus.if.org Git - php/commitdiff
- Fixed bug #48773 (Incorrect error when setting PDO::ATTR_STATEMENT_CLASS with ctor_...
authorFelipe Pena <felipe@php.net>
Sun, 19 Jul 2009 18:55:31 +0000 (18:55 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 19 Jul 2009 18:55:31 +0000 (18:55 +0000)
  [HEAD only]

ext/pdo/pdo_dbh.c
ext/pdo_sqlite/tests/bug48773.phpt [new file with mode: 0644]

index c88b2b782cbf6ed166adba6b87a27c797b411786..283980c8b50cec5647ea12b057fb2b3cde826802 100755 (executable)
@@ -775,8 +775,8 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, long attr, zval *value TSRMLS_D
                        }
                        if (Z_TYPE_P(value) != IS_ARRAY
                                || zend_hash_index_find(Z_ARRVAL_P(value), 0, (void**)&item) == FAILURE
-                               || Z_TYPE_PP(item) != IS_STRING
-                               || zend_lookup_class(Z_STRVAL_PP(item), Z_STRLEN_PP(item), &pce TSRMLS_CC) == FAILURE
+                               || !PDO_ZVAL_PP_IS_TEXT(item)
+                               || zend_u_lookup_class(Z_TYPE_PP(item), Z_UNIVAL_PP(item), Z_UNILEN_PP(item), &pce TSRMLS_CC) == FAILURE
                        ) {
                                pdo_raise_impl_error(dbh, NULL, "HY000", 
                                        "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
diff --git a/ext/pdo_sqlite/tests/bug48773.phpt b/ext/pdo_sqlite/tests/bug48773.phpt
new file mode 100644 (file)
index 0000000..b8bdea9
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Bug #48773 (Incorrect error when setting PDO::ATTR_STATEMENT_CLASS with ctor_args)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
+?>
+--FILE--
+<?php
+
+class bar extends PDOStatement {
+       private function __construct() {
+       }
+}
+
+class foo extends PDO {
+       public $statementClass = 'bar';
+       function __construct($dsn, $username, $password, $driver_options = array()) {
+               $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
+               parent::__construct($dsn, $username, $password, $driver_options);
+
+               $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this)));
+       }
+}
+
+$db = new foo('sqlite::memory:', '', '');
+$stmt = $db->query('SELECT 1');
+var_dump($stmt);
+
+?>
+--EXPECTF--
+object(bar)#%d (1) {
+  [%u|b%"queryString"]=>
+  %unicode|string%(8) "SELECT 1"
+}