File tree Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -2287,15 +2287,18 @@ static const zend_object_iterator_funcs pdo_stmt_iter_funcs = {
2287
2287
2288
2288
zend_object_iterator * pdo_stmt_iter_get (zend_class_entry * ce , zval * object , int by_ref )
2289
2289
{
2290
- pdo_stmt_t * stmt = Z_PDO_STMT_P (object );
2291
- struct php_pdo_iterator * I ;
2292
-
2293
2290
if (by_ref ) {
2294
2291
zend_throw_error (NULL , "An iterator cannot be used with foreach by reference" );
2295
2292
return NULL ;
2296
2293
}
2297
2294
2298
- I = ecalloc (1 , sizeof (struct php_pdo_iterator ));
2295
+ pdo_stmt_t * stmt = Z_PDO_STMT_P (object );
2296
+ if (!stmt -> dbh ) {
2297
+ zend_throw_error (NULL , "PDO object is uninitialized" );
2298
+ return NULL ;
2299
+ }
2300
+
2301
+ struct php_pdo_iterator * I = ecalloc (1 , sizeof (struct php_pdo_iterator ));
2299
2302
zend_iterator_init (& I -> iter );
2300
2303
I -> iter .funcs = & pdo_stmt_iter_funcs ;
2301
2304
Z_ADDREF_P (object );
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Uninitialized PDO objects
3
+ --SKIPIF--
4
+ <?php if (!extension_loaded ('pdo ' )) die ('skip ' ); ?>
5
+ --FILE--
6
+ <?php
7
+
8
+ class MyPDO extends PDO {
9
+ public function __construct () {}
10
+ }
11
+ class MyPDOStatement extends PDOStatement {
12
+ public function __construct () {}
13
+ }
14
+
15
+ $ pdo = new MyPDO ;
16
+ try {
17
+ $ pdo ->query ("foo " );
18
+ } catch (Error $ e ) {
19
+ echo $ e ->getMessage (), "\n" ;
20
+ }
21
+
22
+ $ stmt = new MyPDOStatement ;
23
+ try {
24
+ $ stmt ->fetch ();
25
+ } catch (Error $ e ) {
26
+ echo $ e ->getMessage (), "\n" ;
27
+ }
28
+ $ stmt = new MyPDOStatement ;
29
+ try {
30
+ foreach ($ stmt as $ row ) {}
31
+ } catch (Error $ e ) {
32
+ echo $ e ->getMessage (), "\n" ;
33
+ }
34
+
35
+ ?>
36
+ --EXPECT--
37
+ PDO object is not initialized, constructor was not called
38
+ PDO object is uninitialized
39
+ PDO object is uninitialized
You can’t perform that action at this time.
0 commit comments