A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 year$this->a->b->c->d calling methods from a superclass in php - page 1
User InfoPosts
$this->a->b->c->d calling methods from a superclass in php#1
Hello i want to make something on classes

i want to do a super class which one is my all class is extended on it

            ____  database class
/
chesterx _/______ member class
\
\_____ another class


i want to call the method that is in the database class like this

$this->database->smtelse();



class Hello extends Chesterx{

public function ornekFunc(){
$this->database->getQuery((popularNews();
$this->member->lastRegistered();
}

}


and i want to call a method with its parent class name when i extend my super class to any class

posted date: 2009-04-12 09:45:00


Re: $this->a->b->c->d calling methods from a superclass in php#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-12 09:45:01


Re: $this->a->b->c->d calling methods from a superclass in php#3
I(m not quite sure what you mean by your last sentence but this is perfectly valid:class Chesterx{ public $database, $member; public function __construct(){ $this->database = new database; //Whatever you use to create a database $this->member = new member; }}

posted date: 2009-04-12 09:51:00


Re: $this->a->b->c->d calling methods from a superclass in php#4
i have solved my problem with your answer thanks for help

posted date: 2009-04-12 10:09:00


Re: $this->a->b->c->d calling methods from a superclass in php#5
Consider the Singleton pattern - it usually fits better for database interactions. http://en.wikipedia.org/wiki/Singleton_pattern.

posted date: 2009-04-12 11:43:00


Re: $this->a->b->c->d calling methods from a superclass in php#6
you could also consider using methods to get the sub-ObjectsThe advantage would be that the objecs are not initialized until they are need it, and also provides a much more loosely coupled code that lets you change the way the database is initialized more easy.class Chesterx{ public $database, $member; public function getDatabase() { if (!$this->database ) { $this->database = new database; //Whatever you use to create a database } return $this->database; } public function getMember() { if (!$this->member) { $this->member = new member; } return $this->member; }}

posted date: 2009-04-12 12:33:00


Re: $this->a->b->c->d calling methods from a superclass in php#7
Please, no Singletons.

posted date: 2009-04-24 07:22:00


Re: $this->a->b->c->d calling methods from a superclass in php#8
I'd be curious to hear as to why.

posted date: 2009-05-03 17:14:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.