classes and methods

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sparkle
Forum Newbie
Posts: 7
Joined: Thu Aug 24, 2006 9:14 am

classes and methods

Post by sparkle »

Hi.
Let's say i have two classes, a and b. I would like to use a's methods AND variables inside b's functions. How do i do that?
1.Do i instantiate a inside of b::__construct?
2.Do i use a::function()? - i don't think a::variable would work though
3.Other ideas?

I've read articles about the observer pattern. I don't think i understood much, but i don't think i can use it here, right?

I would like to have a MVC foundation classes-style approach. I want the Model class's methods and variables to be accesible from the Controller, and Controller's methods and variables to be accesible from within the templates of the View.
What would be easier and most straightforward?

Thank you.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

The Observer has nothing to do with it as far as I see it. What you really need is the Registry Pattern :wink:
sparkle
Forum Newbie
Posts: 7
Joined: Thu Aug 24, 2006 9:14 am

Post by sparkle »

Right.Wow.:P
Great, it's the first time i hear of registry. And now if i think about it..it's damn simple. I just didn't see it.
Thanx. If you have any other important reading such as this one you gave me, please:D
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

http://www.patternsforphp.com
http://phpbook.quantum-star.com/doku.php?id=contentlist (<-- We are still writing this book... Actually, we have just started)
Post Reply