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.

BigJobbies
  • 3,633
  • 11
  • 43
  • 66
  • Look up PHP anonymous functions – Joseph Young Sep 12 '16 at 08:18
  • Do you habe a `check_up($something)` call somewhere? – Alexander Sep 12 '16 at 08: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 – Mark Baker Sep 12 '16 at 08:23
  • See for example http://stackoverflow.com/questions/1065188/in-php-5-3-0-what-is-the-function-use-identifier. 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);`. – jeroen Sep 12 '16 at 08:24
  • Thats interesting, quite confusing, but still interesting ... Thanks for putting a name to it for me – BigJobbies Sep 12 '16 at 08:32

1 Answers1

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

Passionate Coder
  • 7,154
  • 2
  • 19
  • 44