PHP Closur edit

Basic closure binding

As seen previously, a closure is nothing but an instance of the Closure class, and different methods can be invoked on them. One of them is bindTo, which, given a closure, will return a new one that is bound to a given object. For example:

<?php

$myClosure = function() {
    echo $this->property;
};

class MyClass
{
    public $property;

    public function __construct($propertyValue)
    {
        $this->property = $propertyValue;
    }
}

$myInstance = new MyClass('Hello world!');
$myBoundClosure = $myClosure->bindTo($myInstance);

$myBoundClosure(); // Shows "Hello world!"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Table Of Contents
15 JSON
16 SOAP
18 cURL
20 XML
37 URLs
45 Closur
73 YAML
82 PDO
94 IMAP
103 APCu
109 PSR
  ↑ ↓ to navigate     ↵ to select     Esc to close