Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.