Assertions should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be TRUE and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain system limits and features.
Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correctly if assertion checking is not activated.
--
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+u...@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/8a897f5c-41b1-436e-95ed-38397cfccead%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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.
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 breakIs 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.
Actually there are some libraries already throwing InivalidArgumentException:Of course yours is using assertion: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.
--
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+u...@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/b38673aa-3cac-4c29-bbc3-69030036dfbf%40googlegroups.com.
Er. Except that's not true. PHP itself throws exceptions only in two very specific cases:
* PDO, if configured to do so.
* random_int()/random_bytes(), if no entropy source can be found.
As noted before, a failed type check in PHP 5 is equivalent to
trigger_error('error message', E_RECOVERABLE_ERROR).
In PHP 7, it's equivalent to
throw new TypeError(...);
(TypeError implementing Throwable, but not being a descendant of \Exception.)
See:
https://3v4l.org/XL0Of
Neither of those are InvalidArgumentException.
The spec very explicitly says that cache failures must be non-fatal to the application. Throwing uncaught exceptions is fatal to the application. In fact, the spec explicitly says that exceptions from the underlying engine (PDO, file system, Redis, whatever) must be caught and normalized to just a normal cache failure so that it's non-fatal.
Remember, we're talking about a very narrow problem space: Passing a non-DateTimeInterface object to a method that expects one. There are no conditions where that is anything other than the programmer screwing up, probably very very close to the call itself. (eg, if you call expiresAt('2016-07-29'), then according to the spec you're just wrong and should fix your damned code. <g>)
If the spec were still subject to change then I'd be more open to InvalidArgumentException, as the class does throw that explicitly in a few other places (that are also "Developer, you're just wrong" cases). As this is just an errata, however, I don' think throws are on the table.
--Larry Garfield
Hm. I would be open to this. We can include the sample code to copy-paste in the errata, and include it in the utlis package.
Does anyone object to this recommendation for the errata? Paul and Robert especially?
--Larry Garfield
On 07/28/2016 11:19 AM, Brent Shaffer wrote:
If we want to mimic a type error, we could do the following:--
$error = sprintf('Argument 1 passed to %s::expiresAt() must be an instance of DateTime, string given', get_class($this));if (class_exists('TypeError')) {throw new \TypeError($error);}trigger_error($error, E_USER_ERROR);
It's verbose but it's the closest we can get to native handling while still obeying the spec.
- Brent
On Wednesday, July 27, 2016 at 11:21:30 AM UTC-7, Brent Shaffer wrote:Unfortunately, there is no way to trigger an E_RECOVERABLE_ERROR. You can only trigger user-level errors, so E_USER_ERROR is the closest you can get. E_USER_ERROR is catchable via set_error_handler(), so this should be approximately the same.
- Brent
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+u...@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/b38673aa-3cac-4c29-bbc3-69030036dfbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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+u...@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/9e949206-2349-1392-35d8-658dc91a0e0a%40garfieldtech.com.
On Thu, Jul 28, 2016 at 5:28 PM, Larry Garfield <la...@garfieldtech.com> wrote:
Hm. I would be open to this. We can include the sample code to copy-paste in the errata, and include it in the utlis package.
Does anyone object to this recommendation for the errata? Paul and Robert especially?
--Larry Garfield
Hey Larry,
Can you ping me on twitter or something when you need my attention, I'm not checking every thread message. You should ping Robert manually too as I doubt he's noticed this, his input will be of value.
I agree with the rejection of non DateTime|DateTimeImmutable parameters to CacheItemInterface::expiresAt($expiration).
I'm happy with the trigger_error() approach that Brent Shaffer provided as a way to mimic PHP5 and PHP7 invalid type handling.
Many thanks,Paul
- What happens when a value cannot be *un*serialized? (return a miss) Should we allow a __PHP_Incomplete_Class? (no)
If a complete and valid value cannot be returned in a type-safe manner for any reason, it's a cache miss. I'd say you're correct per spec.
- What happens when an already expired or negative lifetime item is saved? (invalidate any existing value & return true)
I'd say this is correct. [...]
- What's the rationale for having reserved characters in keys, and why these ones specifically? (no idea)
Reserved for usage in future extensions, like namespacing or tags. Those seemed like the most likely ones we'd want to use.