# [VOTE] Optional Interfaces

- Thread: https://externals.io/message/126747
- Original archive: https://news-web.php.net/php.internals/126747
- Started by Juris Evertovskis on 2025-03-14T08:09:47+00:00
- Messages: 12
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #126747 — Juris Evertovskis — 2025-03-14T08:09:47+00:00

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

Hello,

 

I've opened the vote on the Optional interfaces RFC.

 

https://wiki.php.net/rfc/optional-interfaces

 

Implementation: https://github.com/php/php-src/pull/17288  

Discussion: https://externals.io/message/126185  

 

The voting will be closed on 2025-03-29 00:00:00 UTC.

 

BR,

Juris

---

## #126748 — Jakub Zelenka — 2025-03-14T09:52:58+00:00

URL: https://externals.io/message/126747#126748 · In reply to: #126747

Hi,

https://wiki.php.net/rfc/optional-interfaces
>

I voted yes as we have got a specific use case in core - user stream
wrapper. More details can be found in
https://github.com/php/php-src/issues/10506 .

Regards

Jakub

---

## #126749 — Jakub Zelenka — 2025-03-14T09:57:41+00:00

URL: https://externals.io/message/126747#126749 · In reply to: #126748

> Hi,
>
> https://wiki.php.net/rfc/optional-interfaces
> > […]
>
> I voted yes as we have got a specific use case in core - user stream
> wrapper. More details can be found in
> https://github.com/php/php-src/issues/10506 .
>
>
Ah I should have probably read it first. :) I confused it with optional
methods in interface so this doesn't really help with the above. Still
seems quite useful so keeping my vote.

Regards

Jakub

---

## #126776 — Juris Evertovskis — 2025-03-15T09:23:05+00:00

URL: https://externals.io/message/126747#126776 · In reply to: #126747

> Hello,
> 
> I've opened the vote on the Optional interfaces RFC.
> 
> https://wiki.php.net/rfc/optional-interfaces
> 
> Implementation: https://github.com/php/php-src/pull/17288
> 
> Discussion: https://externals.io/message/126185
> 
> The voting will be closed on 2025-03-29 00:00:00 UTC.
> 
> BR,
> 
> Juris

Hello again,

A reddit discussion has started as well: 
https://www.reddit.com/r/PHP/comments/1jbcbtx/php_rfc_optional_interfaces/

It might be useful to those who haven't made their minds up yet. It 
contains a lot of opinions with both criticism and usecases of this 
feature.

The key point, hoewever, seems to be that the naming of the feature is 
excremental and very easy to misunderstand. I suppose the naming issue 
can be solved separately (if a better name is found) and the 
documentation can use a different naming and description if the RFC 
itself passes.

BR,
Juris

---

## #126782 — drealecs@gmail.com — 2025-03-16T07:18:50+00:00

URL: https://externals.io/message/126747#126782 · In reply to: #126776

> The key point, hoewever, seems to be that the naming of the feature is
> excremental and very easy to misunderstand. I suppose the naming issue can
> be solved separately (if a better name is found) and the documentation can
> use a different naming and description if the RFC itself passes.
>
>
>
Hi Juris,

Looking a bit into the naming issue, it feels like shifting from "optional
interface" to "optionally implements interfaces" is something that could
have help.
The RFC could have used throughout the text the adverb "optionally" to the
verb "to implement" or adjective "optional" to "implementation" instead of
as an adjective to "interface".
Also the name would have been "optional interface implementation".

If you agree, and if the RFC passes, this could at least be documented as
such.

Was not able to find other words that matches better, as all have some
drawbacks.

-- 
Alex

---

## #126867 — Gina P. Banyard — 2025-03-20T16:09:02+00:00

URL: https://externals.io/message/126747#126867 · In reply to: #126776

> 
>
> > […]
>
> Hello again,
>
> A reddit discussion has started as well: https://www.reddit.com/r/PHP/comments/1jbcbtx/php_rfc_optional_interfaces/
>
> It might be useful to those who haven't made their minds up yet. It contains a lot of opinions with both criticism and usecases of this feature.
>
> The key point, hoewever, seems to be that the naming of the feature is excremental and very easy to misunderstand. I suppose the naming issue can be solved separately (if a better name is found) and the documentation can use a different naming and description if the RFC itself passes.

Frankly, the comment from u\phuncky [1] mentioning the possibility of bad interactions with default interface methods (something I think is more important than this) is reinforcing my opinion that this RFC solve the problem in a bad way.
And another user [2] was basically suggesting my previous solution of adding support for type classes/runtime implementation of interfaces.

Best regards,
Gina P. Banyard

[1] [https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhtpwa2/](https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhtpwa2/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button)
[2] [https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhvxo5j/](https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhvxo5j/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button)

---

## #126873 — Larry Garfield — 2025-03-20T17:00:30+00:00

URL: https://externals.io/message/126747#126873 · In reply to: #126867

> Frankly, the comment from u\phuncky [1] mentioning the possibility of 
> bad interactions with default interface methods (something I think is 
> more important than this) is reinforcing my opinion that this RFC solve 
> the problem in a bad way.
> And another user [2] was basically suggesting my previous solution of 
> adding support for type classes/runtime implementation of interfaces.
>
> Best regards,
>
> Gina P. Banyard
>
> [1] https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhtpwa2/ 
> <https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhtpwa2/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button>
> [2] https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhvxo5j/ 
> <https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhvxo5j/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button>

I quite like the Rust-ish style, but given PHP's small compilation units and autoloading needs, I don't know how it could be done.  (Someone wiser than I may know of a way, but I cannot think of one.)

--Larry Garfield

---

## #126883 — tim@bastelstu.be — 2025-03-21T09:50:28+00:00

URL: https://externals.io/message/126747#126883 · In reply to: #126867

Hi

Am 2025-03-20 17:09, schrieb Gina P. Banyard:
> And another user [2] was basically suggesting my previous solution of 
> adding support for type classes/runtime implementation of interfaces.
> […]
> [2] https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhvxo5j/

I don't see how this could (usefully) work in PHP, which doesn't scope 
the methods on a “per interface” basis / which makes methods just some 
syntactic sugar for a function that takes the object as a parameter. 
Once you have more than a handful of interfaces on a single object you 
are bound to have naming / signature conflicts, unless the interfaces 
use some oddly-specific name for their methods. Two different 
serialization libraries might want to use `serialize()` for their 
methods, but using incompatible signatures (e.g. to pass additional 
options).

It works well for Rust, since each trait will need to be imported 
explicitly for the associated methods to be available. And then you can 
also call the method as a free-standing function, just passing the 
appropriate struct as a parameter to disambiguate them.

Best regards
Tim Düsterhus

---

## #126891 — Juris Evertovskis — 2025-03-21T11:17:55+00:00

URL: https://externals.io/message/126747#126891 · In reply to: #126867

> And another user [2] was basically suggesting my previous solution of 
> adding support for type classes/runtime implementation of interfaces.

Hey,

There are two ideas -- the `$object implements Iface` that you suggested 
and the `SomeClass implements Iface` that was suggested on reddit. I see 
the instance-specific one as something that a consumer can do in their 
project if they know that the `$object` actually fits where needed. That 
would be a cool feature per se. But it seems to me it would take a lot 
of bridging code to provide such "dynamically implementing" objects if 
you're the package author.

I'll address the `SomeClass implements Iface` expression vs `class 
SomeClass implements ?Iface` hereinafter.

The `?OptionalInterface` would always be within the class definition and 
in a real-life project with PSR-4 you could check the interface 
existence by inspecting the file tree or click-throughing the name in an 
IDE.

It's not obvious to me how the runtime implementation expressions could 
be in such a discoverable spot. The expression could be anywhere in the 
project. And it will likely be inside conditionals. It would surely be 
hard to discover manually. I'm not a developer of stan tooling, but I 
expect it would complicate automated static analysis as well.

BR,
Juris

---

## #126949 — Ben Ramsey — 2025-03-25T23:56:01+00:00

URL: https://externals.io/message/126747#126949 · In reply to: #126747

> Hello,
>
> I've opened the vote on the Optional interfaces RFC.
>
> https://wiki.php.net/rfc/optional-interfaces
> 
> Implementation: https://github.com/php/php-src/pull/17288
> 
> Discussion: https://externals.io/message/126185
> 
> The voting will be closed on 2025-03-29 00:00:00 UTC.
> 
> BR,
> 
> Juris


I voted "yes" on this.

I've heard from a number of folks over the years who have wanted this 
feature, and the use cases in examples 4 and 5 sold me on it.

I would strongly recommend coming up with a better name for this feature 
in the documentation, and I also think the documentation will need 
strong examples and also describe potential use-cases (like the RFC does).

Cheers,
Ben

---

## #126959 — Levi Morrison — 2025-03-26T18:06:13+00:00

URL: https://externals.io/message/126747#126959 · In reply to: #126747

>
> Hello,
>
>
>
> I’ve opened the vote on the Optional interfaces RFC.
>
>
>
> https://wiki.php.net/rfc/optional-interfaces
>
>
>
> Implementation: https://github.com/php/php-src/pull/17288
>
> Discussion: https://externals.io/message/126185
>
>
>
> The voting will be closed on 2025-03-29 00:00:00 UTC.
>
>
>
> BR,
>
> Juris

I have voted no. I think this could be a good thing, but I was simply
not confident enough in it to vote yes at this time. Maybe in the
future.

---

## #126974 — Juris Evertovskis — 2025-03-29T17:55:25+00:00

URL: https://externals.io/message/126747#126974 · In reply to: #126747

Hello,

 

The voting has concluded with 15 votes in favor and 19 against. As such, the
RFC has been declined.

 

https://wiki.php.net/rfc/optional-interfaces

 

Thank you all for taking the time to consider the proposal and casting your
votes. I'm especially grateful to those who helped refine the RFC by
providing feedback on this list, as well as to those who helped with the
implementation on GitHub.

 

BR,

Juris
