0

Im currently learning my way around OOP, i have come across something in a project that im researching and im not sure what it does.

I was wondering if anyone could explain it to me in a bit of detail.

There are 2 bits, as follows

    $check_up = function($record) {
        return ($record->status == 1);
    };

Im completely lost by this as there is no $record variable set in the entire class, so where is it getting 'status' from ...

and the second example is:

    $check_up = function($record) use($website) {
        return ($record->check < $website->warning);
    };

Any help would be really appreciated to understand this.

5
  • Look up PHP anonymous functions Commented Sep 12, 2016 at 8:18
  • Do you habe a check_up($something) call somewhere? Commented Sep 12, 2016 at 8:19
  • If you say that there is no $record variable defined anywhere in the class, then it's a pretty meaningless anonymous function; but without seeing the rest of the class, we don't know Commented Sep 12, 2016 at 8:23
  • See for example stackoverflow.com/questions/1065188/…. Note that the $record variable is only defined in the local scope of the function. That function could be called in the scope of the $check_up variable using something like $check_up($object_that_has_a_status_property);. Commented Sep 12, 2016 at 8:24
  • Thats interesting, quite confusing, but still interesting ... Thanks for putting a name to it for me Commented Sep 12, 2016 at 8:32

1 Answer 1

2

As Commented try to read this anonymous function

Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses.

http://php.net/manual/en/functions.anonymous.php

Sign up to request clarification or add additional context in comments.

1 Comment

Much appreciated :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.