[nycphp-talk] lazy initialization woes
Sol Toure
sol2ray at gmail.com
Thu Nov 11 09:22:06 EST 2004
> $sales_order = new sales_order;
> $sales_order->has_a( customer );
> print $sales_order->customer->name;
> print $sales_order->customer->name;
>
> the fourth line works, because the customer object was instantiated
> during line three (line three still fails to return a value). Does
> anyone have any suggestions on how to get this working?
Line 3 fails because you do not return anyting from __get()
You should return " $this->$class " from your __get function call.
Line 3 = $undifined->name;
Line 4 succeeds because __get is not called and you have now a new
property "$this->class" that is public by default so therefore
accessed directly.
Line 4 = $customer->name;
More information about the talk
mailing list