Skip to content

Instantly share code, notes, and snippets.

@rocketeerbkw
Created November 10, 2010 06:37
Show Gist options
  • Save rocketeerbkw/670456 to your computer and use it in GitHub Desktop.
Save rocketeerbkw/670456 to your computer and use it in GitHub Desktop.
<?php
// Legacy Code
class Foo {
public $some = 'thing';
public $servers = array('server1', 'server2');
}
// Refactored Foo
class Bar {
private $data = array(
'some' => 'thing',
'servers' => array('server1', 'server2'),
);
public function __get($var) {
return $this->data[$var];
}
}
$foo = new Foo();
echo print_r($foo->servers, true) . PHP_EOL;
$bar = new Bar();
echo print_r($bar->servers, true) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment