Re: RE: RFC: expectations/assertions

From: Date: Tue, 04 Feb 2014 22:53:17 +0000
Subject: Re: RE: RFC: expectations/assertions
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Wed, Feb 5, 2014 at 6:47 AM, Andrea Faulds <[email protected]> wrote:

> On 04/02/14 21:30, Yasuo Ohgaki wrote:
>
>> eval() works.
>>
>> php > assert(eval('FALSE;'));
>>
>> Warning: assert(): Assertion failed in php shell code on line 1
>> php > assert(eval('return FALSE;'));
>>
>> Warning: assert(): Assertion failed in php shell code on line 1
>> php >
>>
>> However, it does not solve inconsistency. PHP code has to be string.
>> Writing PHP code as string is not fun thing to do ;)
>>
>
> That's not what I meant. At present, you do:
>
>     assert($string);
>
> And that string is evaluated. A closure would be faster. Though this is
> for debugging code, so I'm not sure it matters (though I, unlike some
> people, might like to use assertions in production code to make sure things
> fail early, fail often).


I think I understood your comment.

php > assert('function() {return FALSE;}');
php > assert('function() {return TRUE;}');

It does not work, but

php > assert(eval('function() {return FALSE;};'));

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
directly.
It only seems inconsistent to me.

Regards,

--
Yasuo Ohgaki
[email protected]


Thread (44 messages)

« previous php.internals (#72223) next »