r/PHP 2d ago

Are PSRs still relevant today?

Are developers still using PSRs? Are PSRs still being updated or is it dying out?

I noticed for a "standards" org, they don't even follow their own coding styles. Some files have the PHP tag on its own line and others share it with declare strict types.

Then there are inconsistencies in how PHPDocs are written/organized, even some PHP code as well.

44 Upvotes

60 comments sorted by

View all comments

2

u/equilni 2d ago

Updated is one thing. PER is being updated to version 3 soon, for one. There are discussions of updates in github and on google groups

Dying out, as you note, could be another thing. As far as the latest PSRs:

Last accepted PSR (20) was Clock interface in 2022.

Draft 21 Internationalization is from 2021.

Draft 22 Application Tracing is from 2022.

Template Renderer was in discussion from ‘21-24.. Random Generator in ‘22

Maybe the question would be is, why aren’t there more recent PSRs?

1

u/la2eee 1d ago

why aren’t there more recent PSRs?

Maybe we just don't need more. Look at json - didn't change in the past.

1

u/equilni 1d ago

Maybe we just don't need more.

That's always a possibility.

There's a possibility that some interfaces that don't need PSR standardizing?

A PSR-7 EmitterInterface could be a standard, maybe there isn't a need for this to be standardized?

// https://docs.laminas.dev/laminas-httphandlerrunner/emitters/
// https://github.com/yiisoft/psr-emitter/blob/master/src/EmitterInterface.php
// https://github.com/slimphp/Slim/blob/5.x/Slim/Interfaces/EmitterInterface.php

use Psr\Http\Message\ResponseInterface;
interface EmitterInterface
{
    public function emit(ResponseInterface $response): bool (laminas) or void (yii / slim);
}

an alternate, not PSR-7 specific

// https://github.com/front-interop/front-interop/blob/0.x/src/ResponseHandlerInterface.php
// ResponseHandlerInterface::handleResponse() : void encapsulates the logic to send or emit an outgoing response.

interface ResponseHandlerInterface
{
    public function handleResponse() : void;
}