(Stupid GMail, didn't reply automatically to the list)
On Thu, Oct 17, 2013 at 3:41 PM, Michael Wallner <[email protected]> wrote:
> On 17 October 2013 15:34, Marco Schuster <[email protected]> wrote:
>
>> I'd really like to do a simple try-assert-catch instead of writing e.g.
>> if(isset($_GET["foo"]) {
>> throw new InvalidArgumentException('$_GET[foo] not set');
>> }
>>
>> which would become
>> assert(isset($_GET["foo"]));
>>
>> If you're doing a lot of isset-checks, then the assert-way is a bit of
>> an abuse of assert, but it results in far less boilerplate crap. Maybe
>> there's a way that e.g. one can write assertTerminate(cond) or
>> assertException(cond) to differ between the behaviors.
>
> I'm not sure I can follow...
>
> <?php
> function except($assertion, $description=null) {
> if (!$assertion)
> throw new Exception($description);
> }
>
> except(isset($_GET["foo"]))
This forces me to write a description and essentially duplicate the
assertion code, while an AssertionException already contains a
meaningful message ("Assertion in foo.php:1337 failed:
isset($_GET["bar"])!=TRUE").
Marco