1

A friend and I have been bickering on skype for a while now about when magic methods like __get is useful.

For example, say you've got a public/private array:

class test {
    private $array = ['test' => 'blah'];

    public function __get($name) {
        return $this->array[$name];
    }
}

is this a proper application of magic methods? We are arguing because on the php.net page for magic methods it says for 'inaccessible members/properties'. I am of the belief that this means private variables and while it can be used to array things inside of arrays without accessing the array explicitly, that isn't the intended use.

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Stephen K
  • 697
  • 9
  • 26

0 Answers0