Re: [Discuss] Add PDO disconnect() and isConnected()
| From: | Claude Pache | Date: | Wed, 01 Oct 2025 07:11:00 +0000 |
| Subject: | Re: [Discuss] Add PDO disconnect() and isConnected() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128750@lists.php.net to get a copy of this message | ||
> Le 30 sept. 2025 à 14:49, Robert Wolf <rposky@gmail.com> a écrit :
>
> Hello all,
>
> I am announcing discussion phase of RFC "Add PDO disconnect() and isConnected()". As
> the title suggests, this proposes to add a PHP interface to disconnect a PDO client, an alternative
> to the object destructor.
>
> Thank you in advance for your consideration and guidance.
>
> https://wiki.php.net/rfc/pdo_disconnect
>
> -Robert Wolf
>
Hi,
I’ve reviewed my uses of mysqli->close() in the wrapper class around mysqli I wrote several
years ago. All of them were useless, and I have just deleted them after having carefully checked the
documentation. Here is the most obvious case (yes, this is real code):
```php
public function __destruct() {
if ($this->link !== null) {
@ $this->link->close();
$this->link = null;
}
}
```
I wished that mysqli->close() were never implemented...
Methods like mysqli->close() are innocuous by themselves. The issue is that users are tempted,
even incited, to do manual operations that are very well done automatically (in this case, by the
garbage collector). They are also driven to ask themselves questions that they don’t need to
bother (“what if disconnection fails?”).
If you still have good reasons to add such a method in pdo. I recommend to use a name that deters
users from using it in normal operations, e.g. pdo->debug_manual_disconnect().
—Claude