Posted by Darko on 11/06/07 19:53
On Nov 6, 8:37 pm, Good Man <he...@letsgo.com> wrote:
> Hi there
>
> I'm learnin' myself some OO programming (finally), and was wondering if
> someone could briefly tell me why when setting up my object...
>
> $p = new Person();
>
> ... that the following both print "Bob" to the screen:
>
> print $p->name;
> print $p->Name;
>
> The method in the class is getName, so why would "name" (lowercase) work
> here? All my experience in PHP says that uppercase/lowercase is vitally
> important!
>
> Here's the class:
>
> class Person {
>
> function __get($property) {
> $method = "get{$property}";
> if(method_exists($this,$method)) {
> return $this->$method();
> }
> }
>
> function getName() {
> return "Bob";
> }
>
> function getAge() {
> return 44;
> }
>
> }
It's impossible that works. You probably meant $p->getname() and $p-
>getName()
[Back to original message]
|