# PDO subclass names

- Thread: https://externals.io/message/123166
- Original archive: https://news-web.php.net/php.internals/123166
- Started by Saki Takamachi on 2024-04-21T13:00:54+00:00
- Messages: 13
- RFC: Casing of acronyms in class and method names (Accepted) — https://externals.io/rfc/class-naming-acronyms.md
- RFC: Namespaces in bundled PHP extensions (Accepted) — https://externals.io/rfc/namespaces_in_bundled_extensions.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #123166 — Saki Takamachi — 2024-04-21T13:00:54+00:00

URL: https://externals.io/message/123166#123166

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 under the namespace "PDO”? 

e.g.
```
PdoMysql => PDO\Mysql
PdoPgsql => PDO\Pgsql
PdoSqlite => PDO\Sqlite
PdoOdbc => PDO\Odbc
PdoDblib => PDO\Dblib
PdoFirebird => 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”.
https://wiki.php.net/rfc/class-naming-acronyms

I would appreciate hearing your opinions.

Regards,

Saki

---

## #123171 — Matteo Beccati — 2024-04-23T07:59:16+00:00

URL: https://externals.io/message/123166#123171 · In reply to: #123166

Hi Saki,

Il 21/04/2024 15:00, Saki Takamachi ha scritto:
> 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 under the namespace "PDO”?
> 
> e.g.
> ```
> PdoMysql => PDO\Mysql
> PdoPgsql => PDO\Pgsql
> PdoSqlite => PDO\Sqlite
> PdoOdbc => PDO\Odbc
> PdoDblib => PDO\Dblib
> PdoFirebird => 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”.
> https://wiki.php.net/rfc/class-naming-acronyms
> 
> I would appreciate hearing your opinions.

I think you're right's it is almost a "now or never" situation.

It would feel a bit weird that the PDO class and its namespace are 
spelled different (Pdo\Mysql).

ATM, I'm +0 on this.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #123172 — Bilge — 2024-04-23T08:16:48+00:00

URL: https://externals.io/message/123166#123172 · In reply to: #123166

> 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 under the namespace "PDO”?
>
> e.g.
> ```
> PdoMysql => PDO\Mysql
> PdoPgsql => PDO\Pgsql
> PdoSqlite => PDO\Sqlite
> PdoOdbc => PDO\Odbc
> PdoDblib => PDO\Dblib
> PdoFirebird => 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”.
> 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

---

## #123173 — Lynn — 2024-04-23T08:36:20+00:00

URL: https://externals.io/message/123166#123173 · In reply to: #123172

> 
> > […]
> BCMath. While working on that, I learned of the following RFC:
> > […]
> the namespace "PDO”?
> > […]
> so before it's released is last chance to fix this safely.
> > […]
> instead of "PDO”.
> > […]
>
> 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.

---

## #123175 — Stephen Reay — 2024-04-23T09:25:50+00:00

URL: https://externals.io/message/123166#123175 · In reply to: #123173



---

## #123176 — Lynn — 2024-04-23T09:40:38+00:00

URL: https://externals.io/message/123166#123176 · In reply to: #123175

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

>
> Sent from my iPhone
>
> 
>
> ﻿
>
>
> 
>
> > […]
>
> 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.
>
>
> I don't think it's appropriate to claim that a namespace like
> MyLib\HTTP\Client is categorically "wrong".
>
> The argument that "Client" is meaningless becomes pretty moot when you
> realise that you can import a *namespace* and use it relatively, if you so
> wish:
>
> ```
> import MyLib\HTTP;
>
> $a = new HTTP\Client(...);
> ```
>
> I'm not claiming that any particular import pattern is more "correct" (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
> namespaces.
>
> You may as well just go back to MyLib_HTTP_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 list of 20
identical classes to find the one in the right namespace. It requires extra
development and review effort to figure out if the right class called
"Client" or "Factory" is used. For reference, I have 12 "Response", 12
"Client", 20 "Factory", and 20 "TestCase" classes in this project, of which
most are vendors.

Using partially imported namespaces and aliases causes inconsistencies that
makes it harder to find 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.

---

## #123177 — Saki Takamachi — 2024-04-23T10:12:36+00:00

URL: https://externals.io/message/123166#123177 · In reply to: #123176



---

## #123178 — Stephen Reay — 2024-04-23T10:34:53+00:00

URL: https://externals.io/message/123166#123178 · In reply to: #123176



---

## #123181 — Bilge — 2024-04-23T13:04:59+00:00

URL: https://externals.io/message/123166#123181 · In reply to: #123175

> The argument that "Client" is meaningless becomes pretty moot when you 
> realise that you can import a *namespace* and use it relatively, if 
> you so wish:
>
> ```
> import MyLib\HTTP;
>
> $a = new HTTP\Client(...);
> ```

Hi Stephen,

Granted, but I also believe the user can and should have the reasonable 
expectation that they can work comfortably (without conflicts or 
aliases) using leaf (class) names exclusively.

Kind regards,
Bilge

---

## #123182 — Stephen Reay — 2024-04-23T13:17:37+00:00

URL: https://externals.io/message/123166#123182 · In reply to: #123181

Sent from my iPhone

> 
> ﻿On 23/04/2024 10:25, Stephen Reay wrote:
> > […]
> 
> Hi Stephen,
> 
> Granted, but I also believe the user can and should have the reasonable expectation that they can work comfortably (without conflicts or aliases) using leaf (class) names exclusively.
> 
> Kind regards,
> Bilge

I'm sorry but I think you've missed the entire point of namespaces if you want class names to all be universally unique without their namespace component.

The referenced RFC gives clear examples of how a class with a prefix would be converted to a namespace and class.

---

## #123187 — Robert Landers — 2024-04-23T15:13:21+00:00

URL: https://externals.io/message/123166#123187 · In reply to: #123182

>
>
> Sent from my iPhone
>
> > […]
>
> I'm sorry but I think you've missed the entire point of namespaces if you want class names to all be universally unique without their namespace component.
>
> The referenced RFC gives clear examples of how a class with a prefix would be converted to a namespace and class.

As someone who currently works in a codebase with hundreds of *\Mapper
classes, I feel your pain. However, 99% of the time, people are going
to be using a single database implementation at a time per
file/context. If you do find yourself in an edge case where you have
multiple database implementations in the same file, aliases work for
that case.

Robert Landers
Software Engineer
Utrecht NL

---

## #123408 — Saki Takamachi — 2024-05-23T02:45:00+00:00

URL: https://externals.io/message/123166#123408 · In reply to: #123166

Hi all,

If there are no other comments, I'll update this to master.

(There seems to be a discussion going on about class names at the moment, but that goes against the Namespaces RFC and is therefore off-topic for this discussion. If you want to change this, you need to have a separate discussion to override the Namespaces RFC.)

Regards,

Saki

---

## #123411 — Matteo Beccati — 2024-05-23T11:12:15+00:00

URL: https://externals.io/message/123166#123411 · In reply to: #123408

Hi,

Il 23/05/2024 04:45, Saki Takamachi ha scritto:
> Hi all,
> 
> If there are no other comments, I'll update this to master.

+1


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/
