<?php
class Foo {
private $prop;
function __construct($prop) {
$this->prop = $prop;
}
public function getPrinter() {
return function() { echo ucfirst($this->prop); };
}
}
$a = new Foo('bar');;
$func = $a->getPrinter();
$func(); // Outputs: Bar
<?php
$a = new Foo('bar');
$b = new Foo('pickle');
$func = $a->getPrinter();
$func(); // Outputs: Bar
$func = $func->bindTo($b);
$func(); // Outputs: Pickle