Skip to content

Instantly share code, notes, and snippets.

@kurtpayne
Created May 1, 2012 18:04
Show Gist options
  • 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