Created
May 1, 2012 18:04
-
-
Save kurtpayne/2570106 to your computer and use it in GitHub Desktop.
Stupid PHP Tricks - Access a Private Var
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo { | |
private $_bar = ''; | |
public function __construct( $bar ) { | |
$this->_bar = $bar; | |
} | |
public function getBaz( $foo ) { | |
return $foo->_bar; | |
} | |
} | |
$foo1 = new Foo( 'baz' ); | |
$foo2 = new Foo( 'spaz '); | |
echo $foo2->getBaz( $foo1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output is "baz"