Re: [PHP] class effeciency
Hi I too suggested a way for your previous problem. What you are doing is right here, but some corrections are there. You cannot use 'var' to declare variables inside constructors rather you could use them only before constructor, and intialize them inside constructor, look out the below code. ?php class form { var $lang ; function constructor($language) { $lang = $language //.. other stuffs } } In addition you can't intialize them too before constructor. I hope it will work for you. On Thu, 28 Feb 2002, Nick Wilson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all, I have an application that spits out a contact form in either English or Danish. Someone suggested I use a 'class factory' like the PEAR db abstraction layer and that is what I'm doing. So I choose the language like this: $form = Form::GetFormObject($lang); //different class for each lang No problem. My question is related to the efficiency of this. It is only the *properties* that are different in each language class not the methods so I'm including all the same methods twice! That doesn't seem terribly efficient. I thought maybe I could init properties with a constructor in a single class like this: ? function test($lang) { if($lang==en) { var $lang=English; } else if($lang=dk) { var $lang=Danish; } } } ? But it fails. Is there a better way? It just seems like overkill to include 6-700 lines of methods /twice/ Many thanks - -- - --- www.explodingnet.com |Projects, Forums and +Articles for website owners - -- Nick Wilson -- |and designers. -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) iD8DBQE8fe0UHpvrrTa6L5oRAgh5AJ9oXAQ4kMwj/neprZOQx1KZmpOWXACdFTiP WAFmmGoE60Y079p39i+pCnQ= =290x -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php [EMAIL PROTECTED] --- We must use time wisely and forever realize that the time is always ripe to do right. -- Nelson Mandela --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class effeciency
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * and then SMurali Krishna declared Hi I too suggested a way for your previous problem What you are doing is right here, but some corrections are there You cannot use 'var' to declare variables inside constructors rather you could use them only before constructor, and intialize them inside constructor, look out the below code Doh! what an idiot I completely missed that Now I see it it's obvious, thanks once again for your help S - -- - --- wwwexplodingnetcom |Projects, Forums and +Articles for website owners - -- Nick Wilson -- |and designers -BEGIN PGP SIGNATURE- Version: GnuPG v106 (GNU/Linux) iD8DBQE8fg/oHpvrrTa6L5oRAkxnAJ9KJW8jGUaXAQ9TI2NNIF/Mfuu8CQCfVMJf CvJbklp8n3O0fOBS95YCzuM= =MCqF -END PGP SIGNATURE- -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
Re: [PHP] class effeciency
Nick Wilson wrote: Is there a better way? It just seems like overkill to include 6-700 lines of methods /twice/ Use inheritance Define a base class with all of the methods in it Then define the two other classes to extend this base class, meaning they will have all of the methods you have defined but can implement their own variables: http://wwwphpnet/manual/en/keywordextendsphp -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
Re: [PHP] class effeciency
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * and then Simon Willison declared Nick Wilson wrote: Is there a better way? It just seems like overkill to include 6-700 lines of methods /twice/ Use inheritance Define a base class with all of the methods in it Then define the two other classes to extend this base class, meaning they will have all of the methods you have defined but can implement their own variables: http://wwwphpnet/manual/en/keywordextendsphp Hmmm another good answer, I'll get right on it Thanks Simon - -- - --- wwwexplodingnetcom |Projects, Forums and +Articles for website owners - -- Nick Wilson -- |and designers -BEGIN PGP SIGNATURE- Version: GnuPG v106 (GNU/Linux) iD8DBQE8fhCbHpvrrTa6L5oRArgpAJ9XdY4eyY2rK+I1lesFEbS96Z/CMgCgn+8f UdoP8r3CoAly+Rubr08VltY= =e07I -END PGP SIGNATURE- -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
Re: [PHP] class effeciency
On Thu, 28 Feb 2002, Nick Wilson wrote: It is only the *properties* that are different in each language class not the methods so I'm including all the same methods twice! That doesn't seem terribly efficient There is no need to rewrite the methods See: http://wwwphpnet/manual/en/keywordextendsphp -- Mika Tuupola http://wwwappelsiininet/~tuupola/ -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp