Hi!
>> 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
>> 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.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227