Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128745 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 5B7501A00BC for ; Tue, 30 Sep 2025 15:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1759245165; bh=7Xyf2A9KiEUkIg0s0/4zXCzpBFbonSNJVrls7eogV04=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=P+dV7FL4gSWMQu6JHP7sk43YHsm1liAZ0a0FTFY2/PxmdFAaGwMRg0Ow04gj1K0Ih LDJj+LoLHBcyQRo8h/RhiRWg/gvnkJl+LkWiQZMhgloV95dh3zOnXNHo9IrM8a3JFO GDM6PUId3SsGbRfYVOQSd/XzIgzk4O3hAgcHOxY6UM6NLwm8P5KSbaN3gWX30QnqOA RaXu1auyOMKzSerSpUtq2Ns6DNo5H+MDRUpBVZj0BiVJrizOPB/hF9bNLHSr5OutI2 rgjBsqmdEvTZG06Z0vHfjIN7uBz/o2JH0/2oClVjAG32RZTCPEbyGLIOdrfWG2XD3b nVz+TnTUGC4Wg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DDACF1801E8 for ; Tue, 30 Sep 2025 15:12:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 30 Sep 2025 15:12:44 +0000 (UTC) Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-362acd22c78so58712271fa.2 for ; Tue, 30 Sep 2025 08:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759245242; x=1759850042; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7Xyf2A9KiEUkIg0s0/4zXCzpBFbonSNJVrls7eogV04=; b=QcmIO4AgK9LwwS3srdJ1o0WSfTrQwIiVFSGkfA1ZRyAGLds0AhwDjYc7KQcfBDNLtt 4MxIH7juN4hsugsuFyG3YprVQ2AzrN25qh65KbKqip9mpZiHTDqCJJlmROrsLoqhyobD VbADE3aBL9yb0JM7sSCwkIm7G33DtaLYMnvkdO5G7km5Nz2xnmWfbhOtb/Z3VyP8lGhn tyorqiRe5Q9LvQQgOwhARGrSdThKEaiOO3NDTMIlwmjqYWf2tmN4F3qZ/uU6oUMm1uNr hHYA+gqyjqTGAqfsfcIMXoC3Bwco2+z/4Le/6334nZOFbajomT7kMfQAKgEZR7JlIeP4 vENA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759245242; x=1759850042; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7Xyf2A9KiEUkIg0s0/4zXCzpBFbonSNJVrls7eogV04=; b=YXZbCy+NVEbyWXB6M+0LJtb01X/P6+IfR1KOAw5TGEOpVwpkRarnavZ6QqniXlkOsN s+cckCvDCBv8JTHvJm6Oseoa6iQdVeY6QtQsJixKwV5B2nUilhvx1WtCzl6/EAGUm4Tb kCWwAEggrCiONh4cdz+p8FZiyJwgXS862yf9YptfozBJfkylMpiVFrhem3EVOlx1BB38 vT1f9J4sNe8xjjtexx0jIt6QVAbghUvmrShrDu+IHC9dLWMCGngT8ud+I5hRumLOf1e3 JgqOJK8RSK8D2jcU7XodyHzUChIs0WrLVGnXpc9OBZfsELizqqqUU3fUQYzrl1QZXXSn ytXA== X-Forwarded-Encrypted: i=1; AJvYcCXzaaZlxBcJoRXlUIKl/RPFvVLqGUhIh5ZgQD6NBkHrfz0n2mMW5zBMlOFsBq9is5iFIr2Ed3Jm7Rk=@lists.php.net X-Gm-Message-State: AOJu0YzOm6k/hRY2VAu+6GIvXTc1nqNMWxZqO+iweN3EffisliL49x/5 5Kx/Q23F/SATz571nFsf51kBKXu1LQNZGu7T32tBdrrIIpp/+knFJ+ZZQGB2CofHZoWZdXAUl2R b8NlVz5y9Bdg9wyGzgLzJP5PsCuhSGEs= X-Gm-Gg: ASbGncvyCpc8zX7SKNmjQtWoF1cYdot3Ft7kWCefJULttZ+96nVRx9L4EAWTqURnHzO IHm3jOB4kMfTH2HB+9us9Jva3OrXRc3BGxQvAuwBu41IJ8Mi626tdzrYadwPZS+O2O94ZYn642Z lkY0JST8Z+0zTwzEudrR6BNiHg3ioFOJugxwcNpHrf0CCiG4DugkuPXdLk/om3/ThRqVu0pXhr5 h0c/BaUWP4Ki8rKDdiAL+K6RgK7QHM= X-Google-Smtp-Source: AGHT+IG/A5TE0QLdXi9/U3P73xS0DoKIN1QRRGohVFzR8ht+2vKmIeTN2WvBbc5GN5Emq+XJ2ZrMoLyzKdtYZVMd4ZY= X-Received: by 2002:a05:651c:885:b0:36d:4e3b:f1e3 with SMTP id 38308e7fff4ca-36f7ced2040mr61873241fa.13.1759245241786; Tue, 30 Sep 2025 08:14:01 -0700 (PDT) Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 30 Sep 2025 16:13:50 +0100 X-Gm-Features: AS18NWCY6uwY3ZoahzpQSjU0wSkIPphOphi0pfVdegfO4KRMLwtxJxLFbsY_KOs Message-ID: Subject: Re: [PHP-DEV] [Discuss] Add PDO disconnect() and isConnected() To: Andrey Andreev Cc: Robert Wolf , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tekiela246@gmail.com (Kamil Tekiela) On Tue, 30 Sept 2025 at 15:42, Andrey Andreev wrote: > > On Tue, Sep 30, 2025 at 4:56=E2=80=AFPM Kamil Tekiela wrote: >> >> I find this proposal to be a backwards step in the age when we are >> moving away from resources and their explicit closure. We have >> disabled this in PHP 8.0 for curl_close(), imagedestroy(), >> openssl_pkey_free(), shmop_close() and xml_parser_free(). Sure, >> mysqli_close() still works, but the whole extension is mostly a >> historical artefact and a bunch of bad design choices due to what that >> extension is (quick replacement of mysql_* API). PDO was designed much >> better and it deliberately avoided the foot gun that is explicit >> connection closure. I really wish we would not introduce bad design >> choices into the language, and because of this, I wish this proposal >> were unsuccessful. > > > All of the foot gun examples you listed are such because that historic de= sign pattern *required* explicit resource frees, and they are foot guns bec= ause it is easy to forget doing that. > Also, mysqli_close() is the only one that handles a stateful network conn= ection and not a local resource, which is a good reason why it still works. > > There are legitimate use cases where you may want to explicitly and immed= iately close a network connection, even if PHP would do it eventually. > > Cheers, > Andrey. By foot gun, I meant that when such a method exists, the developer can never be sure that the PDO object is in a consistent state. As long as the PDO object is accessible, closing it in one place in the code means that there exists another place in the code where the object is accessible but unusable. This is what gets so many mysqli users. Another issue is that if you call disconnect on PDO object, but you still have PDOStatement with unfetched data, you silently lose the data or get an exception. This situation is more difficult to accidentally arrive at, but still possible. You also lose the ability to call methods such as PDOStatement::execute(). This is not possible today, but by adding disconnect method we introduce a way in which this is possible. PDO isn't a new extension. It has done well without such a function for many years. Maybe there are legitimate use cases for this, but there are also alternatives. Pretty much every time I hear the argument that it would be nice if PDO had it, I can reply with: you can just design your code in a way that doesn't need it. The disconnect method isn't needed for long-running scripts. PHP will disconnect automatically when it determines that the connection is no longer needed, and only then. It's the responsibility of the developer to ensure that they don't keep variables around that aren't necessary anymore.