Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123173 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 qa.php.net (Postfix) with ESMTPS id CB0CD1A009C for ; Tue, 23 Apr 2024 08:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713861450; bh=bqubSbv3UeeORS6wknCWAA8ApqwP503tpEuhAxyrK6Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=flYMxQoIJ8fTpeIVdeOtf0gsR7wbbCrhzB+rvORWVvHlyNCe86pzCIegM+hpKBuej DhtXgVmUbhe/LbtAH4T4/qNHXl7XS7d+D7eSSdrjuLr6fie1cNNzs5xMCL0um6KjRS 6lOJCgqfFFY+U5bp9GD0uVq/bsEq0hQr8tHquR8q7FB6dImU0UIPKsTxrMVSiBhmQf 7cvlEP18Af2y8pBeB3A3ScBiIEQRpAf3s8m5U3lG6ZQAwIpbEknzrrGmiOtA+ObwpR 8tZ5fy8jft+2hpH3eInbAetzUfDrawUy6Y0XhepIOKU3kBvwsJid39BmyTu8dCZfPG tLD3S5t+ot+0A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 940E7180B30 for ; Tue, 23 Apr 2024 08:37:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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, 23 Apr 2024 08:37:29 +0000 (UTC) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a55911bff66so416650966b.0 for ; Tue, 23 Apr 2024 01:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713861408; x=1714466208; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bqubSbv3UeeORS6wknCWAA8ApqwP503tpEuhAxyrK6Q=; b=g3dxtq94Xj6KeyNhOF1/aOu/ib8OGJ9cbPhYph5XX1GtR/BV/BwqaYU8TsFLXXnZhJ bx0YSDp7DPO1/06Rsgp10XAD+2UQhkEvrl3+9rYDsJ1lt3bmcLGy5/gz84DCknKaduyr JHaszJN04tg96L+VgCGUYOJVyX/CgTVkKiab2TP3HCYFVFnHVsmd8+VLMtIDxhFNty67 g8SJjw7H3fQviYX3h1LtFEhdE1Ys6j5nu14QNeo3czq33NUZDJOdus1HJY2kSL/LYbdM 8+SLCa1/Hv9NkNa+x93c1o69SMoClWFcYR+VQKJhTXODO+IeKqyMlau8tp1WIcmU/MVZ aYSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713861408; x=1714466208; h=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=bqubSbv3UeeORS6wknCWAA8ApqwP503tpEuhAxyrK6Q=; b=MYvEgUi4K9vFU4kbXPOcwVksp5J1qvOa5mMyFXirXKtJqC2aPGrhYKDH2J4LlaTrAb z1WNoj+pfAicsubPrgnqadkia5WAQut/nUtf4iWC1KtTos/8bhNzFsMJ1wdhXXzkFsfu 42YTUG9jCYNGrlKA2WDD7TGVen6BHOg4+Zz6pz1rZUBc/BQmTndiSGjl9C94Lob2ccbS 1+GjS3ocvFZnYi+6G2X52esCmjIRGnYkCyLVRWVzWGhrCPxMhjPA2xEcAKukNuSHYvF0 x0F0cLOIFWGZZCXCXj1SLJ70bLQZ5zduF4CcBn6Q9xGai/1fYnLuqJ7GLHYGgtSuy62Q GZoA== X-Gm-Message-State: AOJu0YzdoPiqJu8g+HmAztWTLAkmi3jPUyEbmsRI839HVism+LlOXYMh nl4AkcE8w/NWqHdzIsnEHltiEANOPubGaz02YhKbirxVEsa49Pyt6Z2B9Z7fJIXlt9CLFrOCOpR bcULueV1R6KWwZkkEWAfMOc20a/nNYg== X-Google-Smtp-Source: AGHT+IELdOFp+NHCwypx8stLU/jvbTILGJNQ+HayWwW5c4bTwXN9d3ifAummslGRvWEi5rcIrW4dc8TkDYLYKWV4fws= X-Received: by 2002:a17:906:6bd2:b0:a56:62ee:15a3 with SMTP id t18-20020a1709066bd200b00a5662ee15a3mr2512090ejs.42.1713861407715; Tue, 23 Apr 2024 01:36:47 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <6923C7CF-9168-433C-B2B3-9069F1A766B8@sakiot.com> <512bd0ff-4428-4028-8c59-7fb3f8f01621@scriptfusion.com> In-Reply-To: <512bd0ff-4428-4028-8c59-7fb3f8f01621@scriptfusion.com> Date: Tue, 23 Apr 2024 10:36:20 +0200 Message-ID: Subject: Re: [PHP-DEV] PDO subclass names To: Bilge Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000066baa00616bf746f" From: kjarli@gmail.com (Lynn) --00000000000066baa00616bf746f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 23, 2024 at 10:21=E2=80=AFAM Bilge wro= te: > On 21/04/2024 14:00, Saki Takamachi wrote: > > Hi internals, > > > > Recently I've been working on an RFC regarding object support for > BCMath. While working on that, I learned of the following RFC: > > https://wiki.php.net/rfc/namespaces_in_bundled_extensions > > > > If we follow this RFC, is it reasonable to place subclasses of PDO unde= r > the namespace "PDO=E2=80=9D? > > > > e.g. > > ``` > > PdoMysql =3D> PDO\Mysql > > PdoPgsql =3D> PDO\Pgsql > > PdoSqlite =3D> PDO\Sqlite > > PdoOdbc =3D> PDO\Odbc > > PdoDblib =3D> PDO\Dblib > > PdoFirebird =3D> PDO\Firebird > > ``` > > > > We'll probably get a BC Break if try to fix this after 8.4 is released, > so before it's released is last chance to fix this safely. > > > > If Tim's RFC under discussion is passed, the namespace will be "Pdo" > instead of "PDO=E2=80=9D. > > https://wiki.php.net/rfc/class-naming-acronyms > > > > I would appreciate hearing your opinions. > > > > Regards, > > > > Saki > > Hi Saki, > > Consider that adding a namespace does not/should not change the class > name. That is, `MyClass` once namespaced becomes `MyNamespace\MyClass`. > Ergo, `PdoMysql` becomes `Pdo\PdoMysql`. The class name should still > make sense and be a "strong name" (without conflict) once imported. > > To state it more concretely, I believe it is normal and correct to > include 1-3 namespace components within the class name itself, in order > to create such a "strong name". As a more concrete example of this, > consider `HttpClient`, `FtpClient` and `SoapClient`. Far too often, we > see user libraries (incorrectly) namespace these as `Http\Client`, > `Ftp\Client` and `Soap\Client` (or similar) where the leaf name just > becomes `Client`. "Client", by itself is a meaningless moniker, but that > is all we see once the name is imported, notwithstanding importing > multiple of these clients in one file causes conflicts that now need to > be resolved with local aliases. In general, I believe aliasing to be an > anti-pattern that points to a failure to create strong names and thus > should be avoided by including some of the namespace portion in the > class name to make the class name more meaningful. Once imported, we do > not see the namespace portion within the body of the file any more; > `HttpClient` and `FtpClient` make much more sense by themselves, whether > or not they would otherwise conflict. > > Kind regards, > Bilge > The code base I work in has 25 classes that are called "Line". They have namespaces like `App\Model\Invoice\Line`, this is cumbersome to work with so I would also prefer something like `Pdo\PdoMysql`, even if it's not likely to conflict with a name such as Mysql. --00000000000066baa00616bf746f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Apr 23, 2024 at 10:21=E2=80= =AFAM Bilge <bilge@scriptfusio= n.com> wrote:
On 21/04/2024 14:00, Saki Takamachi wrote:
> Hi internals,
>
> Recently I've been working on an RFC regarding object support for = BCMath. While working on that, I learned of the following RFC:
> https://wiki.php.net/rfc/namespaces_in= _bundled_extensions
>
> If we follow this RFC, is it reasonable to place subclasses of PDO und= er the namespace "PDO=E2=80=9D?
>
> e.g.
> ```
> PdoMysql =3D> PDO\Mysql
> PdoPgsql =3D> PDO\Pgsql
> PdoSqlite =3D> PDO\Sqlite
> PdoOdbc =3D> PDO\Odbc
> PdoDblib =3D> PDO\Dblib
> PdoFirebird =3D> PDO\Firebird
> ```
>
> We'll probably get a BC Break if try to fix this after 8.4 is rele= ased, so before it's released is last chance to fix this safely.
>
> If Tim's RFC under discussion is passed, the namespace will be &qu= ot;Pdo" instead of "PDO=E2=80=9D.
> https://wiki.php.net/rfc/class-naming-acronyms
>
> I would appreciate hearing your opinions.
>
> Regards,
>
> Saki

Hi Saki,

Consider that adding a namespace does not/should not change the class
name. That is, `MyClass` once namespaced becomes `MyNamespace\MyClass`. Ergo, `PdoMysql` becomes `Pdo\PdoMysql`. The class name should still
make sense and be a "strong name" (without conflict) once importe= d.

To state it more concretely, I believe it is normal and correct to
include 1-3 namespace components within the class name itself, in order to create such a "strong name". As a more concrete example of thi= s,
consider `HttpClient`, `FtpClient` and `SoapClient`. Far too often, we
see user libraries (incorrectly) namespace these as `Http\Client`,
`Ftp\Client` and `Soap\Client` (or similar) where the leaf name just
becomes `Client`. "Client", by itself is a meaningless moniker, b= ut that
is all we see once the name is imported, notwithstanding importing
multiple of these clients in one file causes conflicts that now need to be resolved with local aliases. In general, I believe aliasing to be an anti-pattern that points to a failure to create strong names and thus
should be avoided by including some of the namespace portion in the
class name to make the class name more meaningful. Once imported, we do not see the namespace portion within the body of the file any more;
`HttpClient` and `FtpClient` make much more sense by themselves, whether or not they would otherwise conflict.

Kind regards,
Bilge

--00000000000066baa00616bf746f--