Array/Object Recursion?

The problem is that you are linking everything together inside your objects This problem is normally solved by creating a container class that holds the other objects and creates interactions between them To be able to do $main->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->init should give you an indication that something is wrong A possible solution is represented generically below: class Manager { $theme; $uri; $init; } And THEME, URI, and INIT no longer have direct relationships to each other.

The problem is that you are linking everything together inside your objects. This problem is normally solved by creating a container class that holds the other objects and creates interactions between them. To be able to do $main->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->uri->theme->init should give you an indication that something is wrong .. .

A possible solution is represented generically below: class Manager { $theme; $uri; $init; } And THEME, URI, and INIT no longer have direct relationships to each other.

They need to have relations between them. I need to access the functionalities of one class in another one, but do it the way it is done in most frameworks (codeignitier, phpcake,etc) – Dragos Oct 21 at 14:32 What @Levi proposed still gives each object access to all the objects contained within the manager. The only difference is your classes have a dependency on the Manager, and not all with eachother.

– John Cartwright Oct 21 at 14:38 This means that I have to access the other classes like this: $manager->theme; $manager->uri; or $this->manager->theme; etc.. But, I think the way it's done in CodeIgniter is different. – Dragos Oct 21 at 14:41.

I believe your problem is more related to the fact you have instances of each of the other classes inside each other. Theme->uri should not be possible if uri->theme is possible. Only one should have an instance of the other, if either are to have instances of other classes at all.

Think of it like this: I have a Player, he is holding a Bat and a Ball. You have a Player, he is holding a Bat and a Ball, the Bat is holding a Player and a Ball, and the Ball is holding a Bat and a Player. You don't need all those cross-references, you need to establish a sane hierarchy of objects.

The print_r() function will note that it's printing out the same object more than twice and will list it as a *RECURSION* entry. The way that you've organized the objects isn't wrong but consider a different approach, namely, passing only the necessary objects to the constructor. This allows you to clearly see what objects can access and modify which ones and provides better roles for your classes.

For more information you can read up on en.wikipedia.org/wiki/Dependency_injection.

I guess this is exactly what I am doing. I am purposely injecting the isntances of other classes inside a current class, so I can access the other classes by a property of current class. However, I am not sure from that link, if I am doing it wrong or if it's just something normal for such a pattern – Dragos Oct 21 at 14:40 It seems that you're passing an object with all other objects onto every object (confusing).

You should only pass objects that each class requires via the constructor (objects that the class depends on). – Andre Oct 21 at 14:42 Each class has a required dependacy on every other class, except main from which it was extended. – Dragos Oct 21 at 14:46 Can you provide a simplistic example of your class structure?

It would help to have a visual of what you're trying to do. – Andre Oct 21 at 14:48 I have updated the question with the structure. Thanks!

– Dragos Oct 21 at 14:55.

There is a main class, from which all other classes are extended. I am sorry, this is not a direct answer to your question, but if this is the case you are very likely doing something fundamentally wrong. Why is there a need for all classes to extend main?

I think this conceptual problem is the root of your other problems.

2 I agree that he shouldn't be extending main, but that isn't the root of his problem. – Levi Morrison Oct 21 at 14:16 @LeviMorrison He doesn't seem to be extending them through an is-a relationship (inheritance), but with a has-a relationship (main contains instances of other classes. ) In that sense, it very well could be the root of his problem.

– robjb Oct 21 at 14:21 @middus, That seems to be the case and is the problem I noted in my answer, and the one Chris Browne noted after me. That doesn't seem to be clear in your post. If it was, I would have just +1 and moved along and never written an answer.

– Levi Morrison Oct 21 at 14:23 @LeviMorrison: I wrote that comment, not middus. I agree it's not completely clear here. :) – robjb Oct 21 at 14:25 @robjb My apologies, mate.It's early in the morning for me :) – Levi Morrison Oct 21 at 14:31.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions