Re[4]: [PHP] A stupid question about classes

From: Date: Sat, 01 May 2010 20:36:33 +0000
Subject: Re[4]: [PHP] A stupid question about classes
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-304830@lists.php.net to get a copy of this message
Hello Richard, thanks a lot! -- With best regards from Ukraine, Andre Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: m_elensule ----- Original message ----- From: Richard Quadling <rquadling@googlemail.com> To: Andre Polykanine <andre@oire.org> Date: Saturday, May 1, 2010, 10:49:49 PM Subject: [PHP] A stupid question about classes On 1 May 2010 20:38, Andre Polykanine <andre@oire.org> wrote: > Hello Nilesh, > > So could you illustrate a bit the __construct() function, please? > Should I pass those variables as parameters of that function? And what > if I need to change their values?) > Thanks! <?php // The generic class which can act standalone. Class OireMail { // these are required public $smtp_server=""; public $domain=""; public $from=""; public $login=""; public $pass=""; public function __construct($smtp_server = '', $domain = '', $from = '', $login = '', $pass = '') { $this->stmp_server = $smtp_server; $this->domain = $domain; $this->from = $from; $this->login = $login; $this->pass = $pass; } } // Let's create a generic email class and supply all the params. $Mail = new OireMail('Server', 'Domain', 'from@domain.com', 'login', 'Passw0rd'); // A more specialised version of the class with all the required params pre set. Class SpecialisedOireMail extends OireMail { public function __construct() { parent::__construct('SpecServer', 'SpecDomain', 'Spec@SpecDomain.com', 'SpecLogin', 'SpecPassw0rd'); } } // Let's create a specialised version. Note - no need to supply params as the sub-class deals with that. $SpecMail = new SpecialisedOireMail(); var_dump($Mail, $SpecMail); ?> outputs ... object(OireMail)#1 (6) { ["smtp_server"]=> string(0) "" ["domain"]=> string(6) "Domain" ["from"]=> string(15) "from@domain.com" ["login"]=> string(5) "login" ["pass"]=> string(8) "Passw0rd" ["stmp_server"]=> string(6) "Server" } object(SpecialisedOireMail)#2 (6) { ["smtp_server"]=> string(0) "" ["domain"]=> string(10) "SpecDomain" ["from"]=> string(19) "Spec@SpecDomain.com" ["login"]=> string(9) "SpecLogin" ["pass"]=> string(12) "SpecPassw0rd" ["stmp_server"]=> string(10) "SpecServer" } Hope that helps. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling

« previous php.general (#304830) next »