5
5

More than 5 years have passed since last update.

Closure::bind()を使ってprivate変数をすっぱ抜く

Last updated at Posted at 2012-03-09
<?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());
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5