Hi all,
On Wed, Feb 5, 2014 at 4:17 PM, Stas Malyshev <[email protected]>wrote:
> >> php > assert('function() {return FALSE;}');
> >> php > assert('function() {return TRUE;}');
>
> This runs function() code, which produces a closure. The closure is not
> false, so assert is not fired.
>
> >> php > assert(eval('function() {return FALSE;};'));
>
> The eval here returns NULL (http://3v4l.org/cPpgj) so of course assert
> will be fired here. From eval's manual:
> eval() returns NULL unless return is called in the evaluated code, in
> which case the value passed to return is returned.
> Compare:
> http://3v4l.org/vhe1p
> http://3v4l.org/B79r3
Thank you.
It looks I did wrong on my little experiment.
> >> Warning: assert(): Assertion failed in php shell code on line 1
> >>
> >> so closure in eval() works. I don't see reason not to allow closure
>
> Did you try:
> assert(eval('function() {return TRUE;};'));
>
> Testing hypothesis usually involves not only testing something that
> confirms it, but also something that may refute it. Otherwise you're not
> really testing, you are just convincing yourself.
>
> > Added this to inconsistent behaviors RFC to track.
> >
> > https://wiki.php.net/rfc/inconsistent-behaviors#assert
>
> There's no inconsistent behaviors here and IMHO this RFC is turning into
> "things people misunderstand in PHP". Maybe it should be moved to a blog
> or some other space, because it by now has very little to do with what
> RFCs are for.
function func() {}
assert(func());
and
assert(function func() {});
would be better to get the same result. Besides, rather than
$f = function func() {};
assert($f());
This form
assert(function func() {
// some code here
});
is more user friendly and looks more modern language.
I'm sure most users are used to latter form, since this form
is used extensively in JavaScript. It keeps variable scope
clean, too.
I hope new assert() supports direct closure call :)
Regards,
--
Yasuo Ohgaki
[email protected]