At 4/22/09 06:19 AM, Loccie wrote:
I've used OOP in other languages and just started learning it in php as well. What I like to know is if the following is possible and if it is how and if it's good practice.
$myGeneralObject->aSubObject->method();
Perfectly legal. In fact, this is how cakephp implements it's active record (of course, cake php manages to botch the living hell out of active record, making writing methods to act on instances of data damned hard.) As of php 5, you can also do this: $myObject->somemethod1()->somemethod2() so long as somemethod1 returns an object containing somemethod2.
So you have one masterclass and in that class you have different classes for each part of your website. So an object for your members, one for your pages, etc...
Bad idea. Registries (assuming this is what you are talking about), are usually a horrible idea. Every time you want to modify your program, you will almost always have to modify that class. The only time I think they ever remotely make any sense is for storing configuration values. If you want to try something like this, look into the Model View Controller and Front End Controller patterns. Most MVC based frameworks, like cakePHP and codeigniter implement them.
Also, you may want to check out SOLID practices. You can read up more about this here: http://www.oodesign.com/design-principle s.html If you haven't encountered this before, I highly recommend you look into it. I've found these practices to be extremely helpful. It was one of the programmers at newgrounds, (it was Dearon, I believe, but I can't be sure), that directed me to them, and I'm very grateful for it.
At 4/22/09 08:17 AM, Jon-86 wrote:
I'm not sure if PHP supports multiple inheritance, but a quick google gave me this:
http://www.devshed.com/c/a/PHP/Object-In teraction-in-PHP-Introduction-to-Composi tion/
PHP does not support multiple inheritance, but it does support java style interfaces.