Jump to content

can i call a method from the construct


purencool

Recommended Posts

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);

            }

            ?>

 

Link to comment
https://forums.phpfreaks.com/topic/168231-can-i-call-a-method-from-the-construct/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.