Description:
------------
I encountered a segfault after attempting to use the query() method on the PDO class after it had been unexpectedly cloned. This was actually done on 7.2.16, but I don't have the ability to test it on other version at the moment.
Test script:
---------------
<?php
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'testuser';
$pass = 'testpass';
$db1 = new PDO($dsn, $user, $pass);
$result1 = $db1->query("SELECT COUNT(*) FROM `testtable`"); // Will return PDOStatement object
$db2 = clone $db1;
$result2 = $db2->query("SELECT COUNT(*) FROM `testtable`"); // Will segfault
Expected result:
----------------
Since there is no case I can think of where cloning a PDO object is necessary, I think that maybe throwing an exception of clone is used on a PDO object would be an acceptable solution, however as I'm not an active participant in internals I defer to the judgement of those implementing.
This patch can be accomplished in user space as well (though obviously not the perfect solution) by extending the PDO object and implementing a __clone() method that always throws an exception.
Actual result:
--------------
Segmentation Fault

Since there is no internal API to clone or refcount the dbh a clone can not work without driver API change (and even then it is questionable since we can't really clone the network state)
Patch seems fine, except that the test mises a cleanup