Page 2 of 2

Posted: Fri Aug 04, 2006 2:50 pm
by siefkencp
Further, main.php isnt really finished I just got snagged here, neither is action. I just needed to understand if trying to instantiate an object that is not $this object in the classes is a bad design practice....

Which is most certainly what's causing the problem --- I call 1 'user' instance in a class and then another 'user' instance and thats where my problem crops up.

-- Cannot redeclare class action

From what I gather this has nothing to do with the 'action' class and is simply saying that I'm an idiot for making 2 'user' objects and expecting PHP to know which is which. Incedentailly I have tried giving them different names with no avail. Java can do this, I don't know if PHP5 is capable. I guess its just a long winded question to did i structure my OO in a way that will work and makes sense or have I commited an OO sin.

Posted: Fri Aug 04, 2006 4:06 pm
by Christopher
siefkencp wrote:Further, main.php isnt really finished I just got snagged here, neither is action. I just needed to understand if trying to instantiate an object that is not $this object in the classes is a bad design practice....

Which is most certainly what's causing the problem --- I call 1 'user' instance in a class and then another 'user' instance and thats where my problem crops up.

-- Cannot redeclare class action

From what I gather this has nothing to do with the 'action' class and is simply saying that I'm an idiot for making 2 'user' objects and expecting PHP to know which is which. Incedentailly I have tried giving them different names with no avail. Java can do this, I don't know if PHP5 is capable.
Feyd explained the problem. It is that you are including the action class twice in you main file:

Code: Select all

require "inc/user.class.php";
require "inc/ui.class.php";                       // <- action class included in HERE
require "inc/clarification.class.php";
require "inc/action.class.php";                       // <- action class included AGAIN HERE(no _once)
siefkencp wrote:I guess its just a long winded question to did i structure my OO in a way that will work and makes sense or have I commited an OO sin.
By the questions you are asking and the code you posted it is clear that you are not understanding some basic PHP concepts. I would suggest a couple of things:

1. Simplify

2. Don't include files all over the place -- put one class in each file and include them only in one place where needed (main if you don't know)

3. Keep working on improving you OO design and coding skills. Examples of some things I noticed are:
- helper functions like return_date() can just be functions in PHP. No need to clutter up base classes with them.
- naming methods "return_*" is unusual. The usual naming is something like getDate().
- you have a private property $display in your UI class which is not used, but you may think you are
- it might be better practice to pass object around rather than extending a deeply as you are

If you would like, there are a number of people here could would be glad to work though your design and help clean it up and cover some PHP best practices. Just post you design goals/requirements and we can continue by working through your design and code from the top.

Posted: Mon Aug 07, 2006 8:47 am
by siefkencp
arborint wrote: Feyd explained the problem. It is that you are including the action class twice in you main file:

Code: Select all

require "inc/user.class.php";
require "inc/ui.class.php";                       // <- action class included in HERE
require "inc/clarification.class.php";
require "inc/action.class.php";                       // <- action class included AGAIN HERE(no _once)
Thanks for that, I miss understood his explanation.
arborint wrote:2. Don't include files all over the place -- put one class in each file and include them only in one place where needed (main if you don't know)
That was the effect that I was going for while keeping things easy for one person to upkeep through many many changes.
arborint wrote: 3. Keep working on improving you OO design and coding skills. Examples of some things I noticed are:
- helper functions like return_date() can just be functions in PHP. No need to clutter up base classes with them.
- naming methods "return_*" is unusual. The usual naming is something like getDate().
- you have a private property $display in your UI class which is not used, but you may think you are
- it might be better practice to pass object around rather than extending a deeply as you are

If you would like, there are a number of people here could would be glad to work though your design and help clean it up and cover some PHP best practices. Just post you design goals/requirements and we can continue by working through your design and code from the top.
Thanks for the meaningful response. I suppose I just struggle finding people using (and getting help for) PHP at this level as opposed to just procedurally. I'd be happy to take any help on my design practice that the community would be willing to provide.