Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class myActiveRecord
- {
- protected $party = 'Wanna party?';
- public function __get($name) {
- echo 'myActiveRecord __get() called' . '<br />';
- $method = 'get' . ucfirst($name);
- if(method_exists($this, $method)) {
- $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
- foreach($backtrace as $b) {
- if($b['function'] == $method) {
- return parent::__get($name);
- }
- }
- return $this->$method();
- }
- return parent::__get($name);
- }
- }
- class test extends myActiveRecord
- {
- public function getParty()
- {
- echo 'test getParty() called' . '<br />';
- return $this->party;
- }
- //overrides myActiveRecords' __get()
- public function __get($name)
- {
- echo 'test __get() called' . '<br />';
- if ($name == 'party') return $this->$name;
- else return parent::__get($name);
- }
- }
- $test = new test();
- echo '<br />Accessing through ->party :<br />';
- echo $test->party;
- echo '<br />';
- echo '<br />Accessing through getParty() :<br />';
- echo $test->getParty();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement