Skip to content

Instantly share code, notes, and snippets.

@aczietlow
Created November 20, 2014 15:49
Show Gist options
  • Select an option

  • Save aczietlow/fc13216a08f694bf0959 to your computer and use it in GitHub Desktop.

Select an option

Save aczietlow/fc13216a08f694bf0959 to your computer and use it in GitHub Desktop.
Accessing super class private variables
<?php
Class MyClass {
private $string = 'Can\'t touch this!';
public function doStuff() {
$this->string = $this->string . ' Na Na Na Na.';
}
}
Class SubClass extends MyClass {
public function __construct() {
parent::doStuff();
}
public function printStuff() {
$getter = function($myClass) {
return $myClass->string;
};
$getter = Closure::bind($getter, NULL, new MyClass());
print $getter($this);
}
}
$obj = new SubClass();
$obj->printStuff(); // prints stuff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment