There MUST be one use keyword per declaration <-- does this still apply in PHP7

332 views
Skip to first unread message

Julian Vidal

unread,
Feb 2, 2018, 3:05:38 PM2/2/18
to PHP Framework Interoperability Group
I write my projects using PSR-2 enforced by my IDE (PhpStorm) and have phpcs constantly in the background too. While working today, I found something odd that I would like to discuss in this list.

I wrote this:

use App\Services\AuditTrail\Actions\{
   
ModelPreUpdate,
   
ModelPostUpdate,
   
ModelCreated,
   
ModelDeleted
};

But phpcs complains that according to PSR-2 I should use this:

use App\Services\AuditTrail\Actions\ModelPreUpdate;
use App\Services\AuditTrail\Actions\ModelPostUpdate;
use App\Services\AuditTrail\Actions\ModelCreated;
use App\Services\AuditTrail\Actions\ModelDeleted;

I looked it up on the PHP-FIG website and indeed phpcs was right.

Is there a particular reason for this? Seems to me the group use declarations are much more readable and shorter to write/read. 
Or is this maybe something that was decided pre PHP7 when group use declarations didn't exist?

Just curious to know...
Cheers!

Chuck Burgess

unread,
Feb 2, 2018, 3:07:30 PM2/2/18
to php...@googlegroups.com
PSR2 indeed predates PHP7.
CRB

--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/4e4b75f9-cf52-414a-ab6b-4a2a47734f2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alessandro Lai

unread,
Feb 2, 2018, 4:43:49 PM2/2/18
to PHP Framework Interoperability Group
You should take a look at PSR-12, which is in review right now: https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md

Julian Vidal

unread,
Feb 2, 2018, 4:48:35 PM2/2/18
to php...@googlegroups.com
Ah, didn't know about PSR-12. Looks good and indeed contemplates my use case very thoroughly.

--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/vatmISyTjjY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.

To post to this group, send email to php...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages