Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wingly's avatar
Level 29

PHP 8 attributes vs ISP

Hey guys, From the php documentation about the newly introduced attributes: A simple example of attribute usage is to convert an interface that has optional methods to use attributes. Let's assume an ActionHandler interface representing an operation in an application, where some implementations of an action handler require setup and others do not. Instead of requiring all classes that implement ActionHandler to implement a method setUp(), an attribute can be used. One benefit of this approach is that we can use the attribute several times. https://www.php.net/manual/en/language.attributes.overview.php

Do you guys see any benefit of this approach over interface segregation?

0 likes
2 replies
bugsysha's avatar

To me, that is a clear sign that you have too much in your interfaces and you should apply the interface segregation principle.

1 like
bugsysha's avatar

And yeah, attributes are only adding metadata. Nothing more. To me, that is useful when you have something like controller methods to define routes and so on.

Please or to participate in this conversation.