Php how to simplify passing functions as parameters

Source: Internet
Author: User
There are two functions like this: {code ...} $ fn indicates the function operation passed in. I know this can be written: {code ...} on the Internet, we can use HHVM to write: {code ...} I have read the HHVM project and it seems a bit complicated. Is there any simple way to directly use p... there are two functions like this:

function fun1(callable $fn){    return $fn();}

$ Fn indicates the function operation passed in, which can be written as follows:

$num = 5;$res = fun1(function () use ($num) {    $count = 10*$num;    return $count;});

It is said that HHVM can be written as follows:

$res = retry(5, () ==> 10*$num);

I have read about the HHVM project and it seems complicated. Is there any simple way to directly use php to implement this syntax.

Reply content:

There are two functions like this:

function fun1(callable $fn){    return $fn();}

$ Fn indicates the function operation passed in, which can be written as follows:

$num = 5;$res = fun1(function () use ($num) {    $count = 10*$num;    return $count;});

It is said that HHVM can be written as follows:

$res = retry(5, () ==> 10*$num);

I have read about the HHVM project and it seems complicated. Is there any simple way to directly use php to implement this syntax.

Php does not have a shorthand syntax for this. You can only write it honestly.function

At the beginning, I started to pretend to be B, and I couldn't even understand it later.

It should not exist unless you implement a lexical analyzer ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.