110precent
110precent

Reputation: 322

Closure with parameter inside array

I have problem with closure in PHP 5.4

I have array

public function check(){
return ['int'=>['filter'=>2],
'min'=>function($val){
return ['int'=>2,'min'=>$val];
}
]
}

When I use

(new Obj())->check()['int'];

it works. But I don't know how use min with parameter for example 3

I tryed

(new Obj())->check()['min'](3);
(new Obj())->check()['min'(3)];
(new Obj())->check()['min(3)'];

don't work.

Upvotes: 0

Views: 58

Answers (1)

Jon
Jon

Reputation: 437584

PHP's parser is simply not up to the task, so you can't write this expression as you could have in other languages. You will have to use a workaround, for example:

call_user_func((new Obj())->check()['min'], 3));

Or alternatively:

$f = (new Obj())->check()['min'];
$f(3);

Upvotes: 3

Related Questions