On Wednesday, July 27, 2016 at 9:38:48 AM UTC-6, Takashi Matsuo wrote:
>
>
> On Tuesday, July 26, 2016 at 4:01:17 PM UTC-7, Larry Garfield wrote:
>>
>> From http://www.php-fig.org/psr/psr-6/#error-handling
>>
>> " For that reason Implementing Libraries MUST NOT throw exceptions other 
>> than those defined by the interface"
>>
>> The spec explicitly says not to throw exceptions except where explicitly 
>> specified.  We can't recommend throwing an extra exception then without it 
>> being a BC break in the specification, which would affect potentially all 
>> current users of it.  (There are multiple PSR-6 implementations already in 
>> the wild, and no doubt projects using them.)
>>
>> Whatever the arguments for an exception may be, I don't think we can 
>> consider them without a BC break.
>>
>
> Re: BC break
>
> Is this a really big problem? The changes in PSRs doesn't immediately 
> change libraries in the wild. The psr-6 libraries can still provide another 
> major version, so that the users of those libraries can keep the old 
> behavior with the old stables.
>

According to the PSR Workflow, a major version bump would require a 
replacement PSR.  Unless I'm not understanding the bylaw correctly.
 

> Actually there are some libraries already throwing 
> InivalidArgumentException:
> https://github.com/tedious/Stash/blob/master/src/Stash/Item.php#L365
> https://github.com/symfony/cache/blob/master/CacheItem.php#L75
>
> Of course yours is using assertion:
>
> https://github.com/php-fig/cache-util/blob/master/src/BasicCacheItemTrait.php#L69
>
> If we decide on either of assertion or exception, there will be certainly 
> BC breaks in either side, and you can not avoid them :(
> If you can not avoid them, let's think this way; it is just a good chance 
> to learn how to change PSRs :)
>
> Another small benefit of throwing exception is that, it will allow 
> libraries to notify users when it is invalid (for example past date). 
> `CacheItemInterface::expiresAt()` returns the object, so there is no 
> reliable way to notify such errors to users (warnings can be easily 
> neglected, you know?).
>
> Someone unintentionally passes a past date and the value will never be 
> cached, then they might keep banging their heads for hours.
>

For my own part, I would argue that InvalidArgumentException is one used 
internally by PHP itself, so could be considered an exception to the 
exception, since it could as easily come from PHP itself as from a cache 
implementation.  Yes, it's being thrown in a new context, but aren't all 
Exceptions that PHP throws itself implicitly on any list of expected 
Exceptions one's application might receive?

That points to an issue for the Errata to address, of course, in that PHP 
might throw exceptions of its own accord, outside the control of the PSR-6 
lib itself, and to be aware of the built-in ones when using a PSR-6 
implementation.  It also points to at least two implementations not 
actually following the spec as currently written, but again, for my part, 
their choice can be fairly easily justified, despite actually violating the 
spec.

So, +1 for InvalidArgumentException and an Errata note that built-in 
descendants of Exception are implicitly approved on any interface, if for 
no other reason than PHP itself might throw them before the implementation 
even gets control.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/0ea97913-5db3-432a-ab48-01dcae1d881d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to