Question about autoloading

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

kyberfabrikken wrote:
d11wtq wrote: These methods come in really useful at times. I use __get() and __set() in my abstract View component (just like many others do), but I also provide setVar() and getVar() in the View too. They're just convenience methods really.
I think arborint's point was that the implementation is sketchy. C#'s "properties" are a much nicer implementation of basically the same functionality.
Ah sorry, I misunderstood :)

C# is something I've yet to look at but have always felt held back by the fact I'm not a Windows guys and Mono confused the hell outta me :P
User avatar
kyberfabrikken
Forum Commoner
Posts: 84
Joined: Tue Jul 20, 2004 10:27 am

Post by kyberfabrikken »

d11wtq wrote:C# is something I've yet to look at but have always felt held back by the fact I'm not a Windows guys and Mono confused the hell outta me :P
Here's how C# does it:

Code: Select all

public class Foo
{
  private string __name;
  public string name
  {
    get { return this.__name; }
    set { this.__name = value; }
  }
}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ah, that's clever. It's like a refactored (albeit syntactically different) equivalent, more targetted at specific fields.

Thanks for the example, I agree that __get() and __set() do not do such a good job of this. I think the PHP developers are hard pushed to add new rules to the simplistic PHP syntax though. I suspect this is the same reason they are still faffing about with namespaces and leaving us wondering if they'll actually implement them.

You can direct calls to __get() and __set() with a simple swicth but I admit it's less readable than the approach C# have taken.

Apologies for derailing a thread about autoloading ~Everah :oops:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

d11wtq wrote:Apologies for derailing a thread about autoloading ~Everah :oops:
Aw, it's alright. This thread has been very educational for me.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

kyberfabrikken wrote:I think arborint's point was that the implementation is sketchy. C#'s "properties" are a much nicer implementation of basically the same functionality.
Thanks kyber for the clarification and the excellent example. :)

For the record, I am not saying that I know that the current implementation is not the best one. And I admit it is workable and getting more workable. I think my concern comes from my belief that good design comes from implementation knowledge. Because I have watched Zend "learn as the go" about OOP and enterprise patterns like MVC as they build their framework -- and still not quite get it -- I am suspicious of their solutions in this area. However the chances that I am completly incorrect are, as usual, high.
(#10850)
Post Reply