Hi.
I'm messing with OOP and cannot understand one thing.
If you have Core class, from which you call all other classes, how can the sub classes access each other.
I tried to make them accessible via $this, but it doesnt seem to work. Tried to make methods public but it didnt help.
Like in Subclass1 you call $this->subclass2->method_from_subclass2 and vice versa.
Subclasses in this case are classes called from Core.
Thanks.
OOP MVC
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: OOP MVC
I'm not sure I understand. Are you extending a class? Some code would help.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: OOP MVC
yes, I am extending.
class Core {}
class Library1 extends Core { function test1() {} }
class Library2 extends Core { function test2() {} }
For example, I want to call $this->library2->test2() from Library1 and so on.
class Core {}
class Library1 extends Core { function test1() {} }
class Library2 extends Core { function test2() {} }
For example, I want to call $this->library2->test2() from Library1 and so on.
Re: OOP MVC
I think he wants to do the singleton pattern. Either way, good link.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: OOP MVC
I think your design methodology is flawed. If you instantiate an object from class Library1 how can you use an object from class Library2 if it hasn't been instantiated yet? You can call statically:
Or if you needed the object then I guess in Library1 you could do this:
Code: Select all
Library2::test2();Code: Select all
$this->library2 = new Library2;mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: OOP MVC
Yes, Singleton Pattern looks similar to what I tried to make.
Can anyone tell what are cons and pros of using Singleton for MVC framework ?
AbraCadaver, I thought it could be possible because I already called both classes in the Core class. Oh, I missed to say that before.
class Core {
function __construct(){
$this->lib1 = new Library1;
$this->lib2 = new Library2;
}
}
Can anyone tell what are cons and pros of using Singleton for MVC framework ?
AbraCadaver, I thought it could be possible because I already called both classes in the Core class. Oh, I missed to say that before.
class Core {
function __construct(){
$this->lib1 = new Library1;
$this->lib2 = new Library2;
}
}
Re: OOP MVC
Imagine the main class "Core" to be called "Dog". Imagine Library 1 to be "Alsatian" and Library 2 to be "Labrador". You can't make an Alsation do Labrador-specific things, or a Labrador do Alsation-specific things. They can only do their own specific things and general Dog things.vilis wrote:I thought it could be possible because I already called both classes in the Core class. Oh, I missed to say that before.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: OOP MVC
If you search, you can find tons of information about using the Singleton. As for in a "MVC framework", I noticed that Zend is removing most of the Singletons for its 2.0 release. There is probably a discussion of that decision somewhere.vilis wrote:Can anyone tell what are cons and pros of using Singleton for MVC framework ?
PS - "OOP MVC" has to be the ultimate buzzcronym post title for a PHP forum! Well done!
(#10850)