Skip to content

Instantly share code, notes, and snippets.

@kurtpayne
Created May 1, 2012 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtpayne/2570106 to your computer and use it in GitHub Desktop.
Save kurtpayne/2570106 to your computer and use it in GitHub Desktop.
Stupid PHP Tricks - Access a Private Var
<?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 );
@kurtpayne
Copy link
Author

Output is "baz"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment