<?php
/**
* http://jp2.php.net/manual/ja/closure.bind.php
*
* @author Katsuhiro Ogawa
*/
class Wozozo
{
private $secret = 'happy';
}
$wozozo = new Wozozo();
//$wozozo->secret;
// -> Fatal error: Cannot access private property Wozozo::$secret
$moriyoshi = Closure::bind(function() {
return $this->secret;
}, $wozozo, 'Wozozo');
var_dump($moriyoshi());
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme