How do you use an anonymous function inside a class in PHP?

The fact that you call greet makes PHP treat it like a function and not a property. You can have the same name for both a property and method in PHP, so the distinction is relevant.

PHP 7+

In PHP7 the __call() method is no longer needed to call closures bound to properties, because of Uniform Variable Syntax. This will allow you to add parentheses around any code, just like you do in arithmetics.

class Model
{
    public $greet;
    function __construct()
    {
        $this->greet = function($name)
        {
            printf("Hello %s\r\n", $name);
        };
    }
}

$test = new Model();
($test->greet)('johnny');

PHP 5

What you can doe as a workaround is use the __call() magic method. It will catch the call to the undefined greet method.

class Model
{
    public $greet;
    function __construct()
    {
        $this->greet = function($name)
        {
            printf("Hello %s\r\n", $name);
        };
    }

    function __call($method, $args)
    {
        if (isset($this->$method) && $this->$method instanceof \Closure) {
            return call_user_func_array($this->$method, $args);
        }

        trigger_error("Call to undefined method " . get_called_class() . '::' . $method, E_USER_ERROR);
    }
}

$test = new Model();
$test->greet('johnny');

You cannot initialize object variables with the results of expressions. Only static/constant values are allowed. e.g.

class foo {
   public $bar = 1+1; // illegal - cannot use an expression
   public $baz = 2; // valid. '2' is a constant
}

You'd have to do:

class foo {
   public $bar;
   function __construct() {
        $this->bar = function() { .... }
   }
}

And to actually invoke the closure, as per this answer:

$x = new foo()
$x->bar->__invoke();