Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123177 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 7BB4B1A009C for ; Tue, 23 Apr 2024 10:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713867215; bh=g9rY8jyLbGN1ch5eHNyzyQlGlaznKWgo1KKwNYarKwI=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=mswW2hPV1MrMm9pQmq9ZPOL5iVAdtDdjChdoqWRPf5r4N3uti6zXaAdufh0YMnc7Z uJ/5cF5pxm4PsnhlOyN3WXl89hV7BJ0aBr5X6GXucsTbQ2Pc87I2hGo1oJy1rfmpFV GT1QLEuE18Q2xDcY8wDecoQ1/RV3r7xBmxL0rt5Q0n6EvT8C414ccEtHJ9S+lCV8Nc ZUP7gp7boxqmBs8YY5p7CAPOEmSScjcc6NPBgoHf5dNkpY6qfCa7lyDn/Qb22P4xop 6HZ15JZkklkYDthgJc1g60fohMG8JY/LUPdPm/qMRJNc/HH5sFeQSQlgKjs193YH/P LMFpYUV0DP9DA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6CC8B180E0E for ; Tue, 23 Apr 2024 10:13:33 +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=1.5 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MIME_QP_LONG_LINE,MPART_ALT_DIFF, 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.sakiot.com (mail.sakiot.com [160.16.227.216]) (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 10:13:32 +0000 (UTC) Received: from smtpclient.apple (233.66.239.49.rev.vmobile.jp [49.239.66.233]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id EB6FD401E2; Tue, 23 Apr 2024 19:12:48 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1713867169; bh=g9rY8jyLbGN1ch5eHNyzyQlGlaznKWgo1KKwNYarKwI=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=hCL4LCiTztQFGBir9ThhOZpnwWz7mZsjRoKJS7Rpdz5V92VIG85qsDYWTO4JUI6Dm 56sb/DUZNtuNuHcPsjy6fC4kNj5RHDI+jbTJlRwNsNGs+wJIEDnXVwqwrHlPkYlSKA 7Ez3x3Lm/t1RZneCS0TAq3dNAhS2tb+ZIwXjGWaM= Content-Type: multipart/alternative; boundary=Apple-Mail-A22DD69B-27D9-4E5F-8F81-626FE5FF68E8 Content-Transfer-Encoding: 7bit Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] PDO subclass names Date: Tue, 23 Apr 2024 19:12:36 +0900 Message-ID: References: Cc: Stephen Reay , Bilge , internals@lists.php.net In-Reply-To: To: Lynn X-Mailer: iPhone Mail (21E236) From: saki@sakiot.com (Saki Takamachi) --Apple-Mail-A22DD69B-27D9-4E5F-8F81-626FE5FF68E8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi a= ll,

On Tue, Apr 23= , 2024 at 11:26=E2=80=AFAM Stephen Reay <php-lists@koalephant.com> wrote:

Sent from my iPhon= e

On 23 Apr 2024, at 18:= 21, Lynn <kjarli@gm= ail.com> wrote:

<= div dir=3D"ltr">=EF=BB=BF


On Tue, Apr 23= , 2024 at 10:21=E2=80=AFAM Bilge <bilge@scriptfusion.com> wrote:
On 21/04/2024 14:00, Saki Takamachi w= rote:
> Hi internals,
>
> Recently I've been working on an RFC regarding object support for BCMat= h. While working on that, I learned of the following RFC:
> https://wiki.php.net/rfc/namespaces_in_b= undled_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" in= stead of "PDO=E2=80=9D.
> https://wiki.php.net/rfc/class-naming-acronyms<= br> >
> 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 cla= sses that are called "Line". They have namespaces like `App\Model\Invoice\Li= ne`, 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= .

I don't think it's appropriate to claim that a n= amespace like MyLib\HTTP\Client is categorically "wrong".

The argument that "Client" is meaningless becomes pretty moot when yo= u realise that you can import a *namespace* and use it relatively, if you so= wish: 

```
import MyLib\HTTP;
=

$a =3D new HTTP\Client(...);
```
I'm not claiming that any particular import pattern is more "cor= rect" (and I think it's a bad idea to suggest that other usage patterns are "= incorrect") but adding repetitive prefixes kind of defeats the purpose of na= mespaces.

You may as well just go back to MyLib_HTT= P_Client, and ignore that namespaces exist. 

In your own codebase you should do what works best for you= . When it comes to vendor classes I don't want to have to scroll through a l= ist of 20 identical classes to find the one in the right namespace. It requi= res extra development and review effort to figure out if the right class cal= led "Client" or "Factory" is used. For reference, I have 12 "Response", 12 "= Client", 20 "Factory", and 20 "TestCase" classes in this project, of wh= ich most are vendors. 

Using partially imp= orted namespaces and aliases causes inconsistencies that makes it harder to f= ind things. Nobody here is advocating for MyLibHttpClient class names either= . Even in an IDE like Intellij with a project the size I'm working with it's= hard to quickly get the right classes, especially in legacy code where some= classes live in the global namespace.

First, there are two things I want to make clear= :

1. RFC: Class Naming [1] clearly defines that cla= ss names should be in camel case, excluding acronyms, so currently `PDO` can= not be `Pdo'.  However, if the currently voting RFC: Casing of acronyms= in class and method names [2] passes, acronyms will also need to be camel c= ase, so we'll use `Pdo`.

2. For example, `HttpClien= t` becomes `Http\Client` if follow the guidelines laid out in RFC: Namespace= s in bundled PHP extensions [3]. These rules are clearly stated in the RFC.<= /div>


Regards,

S= aki
= --Apple-Mail-A22DD69B-27D9-4E5F-8F81-626FE5FF68E8--