Re: RE: RFC: expectations/assertions

From: Date: Wed, 05 Feb 2014 20:49:55 +0000
Subject: Re: RE: RFC: expectations/assertions
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi Rowan,

On Wed, Feb 5, 2014 at 7:08 PM, Rowan Collins <[email protected]>wrote:

> function foo($arg)
> {
>     assert ( (function() use ($arg) {
>         $assert_private_var = some_function();
>         return $arg == $assert_private_var;
>     })(), 'oops' );
> }
>
> Not pretty, but it would give you your local scope.
>

I agree, some thing like this is needed to call closure or pass arguments
to assert() then call.
It better than using scope. IMO.

BTW, if we would like to write down all of assert() related code inside
current assert(),
it seems this works. It still pollutes scope, though.

php > $v = 555;
php > assert(($f = function($v) {var_dump($v);return $v < 0;}) && ($f($v)));
int(555)
Warning: assert(): Assertion failed in php shell code on line 1

This may be the way to use new assert.

assert(
  ($f = function($v)
  {
    var_dump($v);return $v < 0;
  })
  &&
  ($f($v)),
  'Do not pass bad value'
);

It does not look good, but not too bad.

Regards,

--
Yasuo Ohgaki
[email protected]


Thread (44 messages)

« previous php.internals (#72295) next »