Re: RE: RFC: expectations/assertions

From: Date: Wed, 05 Feb 2014 07:58:10 +0000
Subject: Re: RE: RFC: expectations/assertions
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-72247@lists.php.net to get a copy of this message
Hi!

> function func() {}
> assert(func());
> 
> and
> 
> assert(function func() {});
> 
> would be better to get the same result. Besides, rather than

It won't be the same result, because first is a function call, and the
second one is not even an expression in PHP, it's function definition.
But if it were anonymous function, it would return function and not the
result on the function call.

> This form
> 
> assert(function func() {
>   // some code here
> });

You probably meant to write a closure (anonymous function) there. So you
actually want assert to support calling closures. This would be a BC
break, but it is very easy to make your own assert that does just that.

> I'm sure most users are used to latter form, since this form
> is used extensively in JavaScript. It keeps variable scope
> clean, too.

No users of PHP are used to this form since this form does not exist in
PHP. As for Javascript users, there's no assert in standards, but many
browsers support console.assert - which works exactly like PHP assert
(without eval stuff) and does not support calling closures either.
See e.g. http://stackoverflow.com/q/15313418/214196
So I wonder how Javascript users would get used to that?
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227


Thread (44 messages)

« previous php.internals (#72247) next »