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]