Hi Dmitry,
On Wed, Feb 5, 2014 at 3:30 AM, Dmitry Stogov <[email protected]> wrote:
> I don't think PHP needs new language constructs for assertions.
> Actually, the code from your example may be implemented as two calls to
> assert().
>
> assert(extension_loaded('foo'), 'You need foo module');
> assert(extension_loaded('bar'), 'You need bar module');
>
> I think it's much clear then inventing new syntax.
> With Joe's proposal these asserts might be completely eliminated.
> And it's backward and forward compatible :)
>
> BTW: I didn't follow all the discussion, so I may miss some points.
>
Thank you for reply.
Since new assert() could be eliminate runtime overheads, it may be the
way to go. Regarding assert(), it seems current assert() is inconsistent
for function calls.
Function call works
php > function f() {return FALSE;}
php > assert(f());
Warning: assert(): Assertion failed in php shell code on line 1
Closure does not
php > assert(function() {return FALSE;});
php >
Closure is a valid expression and it should be allowed. IMO.
Allowing callable as 1st parameter makes behavior consistent.
Closure is useful to keep clean name space.
Could you consider this for new assert?
Regards,
--
Yasuo Ohgaki
[email protected]