purencool Posted July 31, 2009 Share Posted July 31, 2009 hi phpfreaks I have been playing with oop again! In the code below are you able to call methods in the construct? Is it technically correct? If not, once the construct is initializes in this class I can do the calculations so that I can place the information into a getter variable so I don't see the need to call another method other than a getter. <?php //hands on chapter 6-2 class Chapter6handson2{ private $guestNameClass ; private $attendanceClass ; private $guestscomingClass; function _construct (){ $this->guestNameClass= $guestName; $this->attendaceClass = $attendance; $this->guestcommingclass = $guestscoming; if ($this->attendanceClass == no){ no(); } else { yes(); } } function yes(){ } function no(){ } } if(empty($_GET['guestname']) || !isset($_GET['attendance']) || !is_numeric($_GET['guestscoming'])){ echo "<p>Sorry the RVSP Invitation was not completed properly please fill it out again</p>"; } else { $guestName = $_GET['guestname']; $attendance = $_GET['attendance']; $guestscoming = $_GET['guestscoming']; //create object and initiles the variables $weddingInviteGet = new ChFiveGuess($guestName , $attendance , $guestscoming); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/168231-can-i-call-a-method-from-the-construct/ Share on other sites More sharing options...
.josh Posted July 31, 2009 Share Posted July 31, 2009 You can do that, yes. Now whether it is considered bad practice or not...I don't know, as I'm not really that great at OOP either. Quote Link to comment https://forums.phpfreaks.com/topic/168231-can-i-call-a-method-from-the-construct/#findComment-887366 Share on other sites More sharing options...
abazoskib Posted July 31, 2009 Share Posted July 31, 2009 That is fine. In Java, when you build a constructor for a class, it has to call some kind of function to get the class running, such as a display initialization of a GUI. That being said, I think it is all a matter of preference, I would just stay away from putting too many functions in there or you will be defeating the purpose of OOP. Quote Link to comment https://forums.phpfreaks.com/topic/168231-can-i-call-a-method-from-the-construct/#findComment-887391 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.