MasterACE14 Posted August 14, 2011 Share Posted August 14, 2011 Hello, I have a simple(debatable stupid) question. Is there any difference between the following? and is there any problems associated with any of the following? and... which is best practice? function __construct() { } // 1 private function __construct() { } // 2 public function __construct() { } // 3 Kind Regards, Ace Quote Link to comment https://forums.phpfreaks.com/topic/244717-constructor-standard/ Share on other sites More sharing options...
phpSensei Posted August 14, 2011 Share Posted August 14, 2011 Well depends, if the construct method is being called by other classes then the scope would make a difference... With Abstract classes is another example too, but heres a basic one. example Fatal error: Cannot call private Class1::__construct() in /Applications/XAMPP/xamppfiles/htdocs/test.php on line 16 <?php class Class1{ private function __construct(){ print "This is class 1"; } } class Class2 extends Class1{ function __construct(){ parent::__construct(); } } $test = new Class2(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244717-constructor-standard/#findComment-1256972 Share on other sites More sharing options...
MasterACE14 Posted August 14, 2011 Author Share Posted August 14, 2011 ahhhhh, makes sense! Thanks phpSensei. Appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/244717-constructor-standard/#findComment-1256973 Share on other sites More sharing options...
phpSensei Posted August 14, 2011 Share Posted August 14, 2011 Np, i'll get to your other question, i have my handsss full with food. Quote Link to comment https://forums.phpfreaks.com/topic/244717-constructor-standard/#findComment-1256974 Share on other sites More sharing options...
MasterACE14 Posted August 14, 2011 Author Share Posted August 14, 2011 Np, i'll get to your other question, i have my handsss full with food. lol no worries, now I'm hungry... Quote Link to comment https://forums.phpfreaks.com/topic/244717-constructor-standard/#findComment-1256980 Share on other sites More sharing options...
phpSensei Posted August 14, 2011 Share Posted August 14, 2011 haha, less coding more eating man Quote Link to comment https://forums.phpfreaks.com/topic/244717-constructor-standard/#findComment-1257025 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.