Skip to content

Commit a2b8a62

Browse files
committed
Follow up #77849 PDOStatement objects in undefined state after clone
1 parent 9ec1525 commit a2b8a62

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,22 +2266,6 @@ static int dbstmt_compare(zval *object1, zval *object2)
22662266
return -1;
22672267
}
22682268

2269-
static zend_object *dbstmt_clone_obj(zval *zobject)
2270-
{
2271-
pdo_stmt_t *stmt;
2272-
pdo_stmt_t *old_stmt;
2273-
2274-
stmt = ecalloc(1, sizeof(pdo_stmt_t) + zend_object_properties_size(Z_OBJCE_P(zobject)));
2275-
zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject));
2276-
object_properties_init(&stmt->std, Z_OBJCE_P(zobject));
2277-
2278-
old_stmt = Z_PDO_STMT_P(zobject);
2279-
2280-
zend_objects_clone_members(&stmt->std, &old_stmt->std);
2281-
2282-
return &stmt->std;
2283-
}
2284-
22852269
zend_object_handlers pdo_dbstmt_object_handlers;
22862270
static int pdo_row_serialize(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data);
22872271

@@ -2304,7 +2288,7 @@ void pdo_stmt_init(void)
23042288
pdo_dbstmt_object_handlers.unset_property = dbstmt_prop_delete;
23052289
pdo_dbstmt_object_handlers.get_method = dbstmt_method_get;
23062290
pdo_dbstmt_object_handlers.compare_objects = dbstmt_compare;
2307-
pdo_dbstmt_object_handlers.clone_obj = dbstmt_clone_obj;
2291+
pdo_dbstmt_object_handlers.clone_obj = NULL;
23082292

23092293
INIT_CLASS_ENTRY(ce, "PDORow", pdo_row_functions);
23102294
pdo_row_ce = zend_register_internal_class(&ce);

ext/pdo/tests/bug_77849_2.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
PDO Common: Bug #77849 (inconsistent state of cloned statament object)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo')) die('skip');
6+
?>
7+
--FILE--
8+
<?php
9+
$stmt = new PDOStatement();
10+
11+
clone $stmt;
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Error: Trying to clone an uncloneable object of class PDOStatement in %s:4
15+
Stack trace:
16+
#0 {main}
17+
thrown in %s on line 4
18+

0 commit comments

Comments
 (0)