Ellrion
1/22/2016 - 7:48 AM

unprotected

unprotected

<?php
class Foo
{
    private $_bar;
    protected $bar;

    public function __construct($bar)
    {
        $this->_bar = $bar;
        $this->bar = $bar;
    }

    public function showMePrivate($foo)
    {
        echo 'private:' . $foo->_bar, PHP_EOL;
    }

    public function showMeProtected($foo)
    {
        echo 'protected:' . $foo->bar, PHP_EOL;
    }
}

class FooWrap extends Foo
{
    public static function wrap(Foo $base)
    {
        return new self($base->bar);
    }

    public function show()
    {
        echo $this->bar, PHP_EOL;
    }
}

$base = new Foo('text');

$foo = new Foo('some');
$foo->showMeProtected($base);
$foo->showMePrivate($base);

$wrap = FooWrap::wrap($base);
$wrap->show();

$foo->showMeProtected($wrap);
$foo->showMePrivate($wrap);