SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OOP class design question...

    I have this:

    Code:
    <?php
    
    class User{
    
    var $userid;
    var $username;
    var $firstname;
    var $lastname;
    var $password;
    var $email;
    var $signupdate;
    var $lastlogin;
    var $city;
    var $state;
    var $zip;
    var $registrationstatus;
    var $activestatus;
    var $forumname;
    
    function User($userId){
    	$this->userid=$userId;
    }
    
    function getFirstName(){
    
    //get firstname;
    }
    
    }//end class User
    
    //**********************************************
    
    class Trainer extends User{
    
    var $experience;
    var $trainerstyle;
    var $reasonfortraining;
    var $fieldofstudy;
    var $degree;
    var $yearsofexperience;
    var $certifications;
    var $educationalbackground;
    var $specialization;
    var $liabilityinsurance;
    var $cpr;
    
    function Trainer($id){
    
    }
    }
    //**********************************************
    ?>
    
    $Trainer = new Trainer(34);
    $Trainer->getFirstName();
    At the bottom I need to get the firstname, but how do I get the first name from the User class, if I instantiated the Trainer class....in other words, how do I pass the userId to the parent class?

    Paul

  2. #2
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because Trainer extends User, you simply need to make the code in User like this:
    PHP Code:
    function getFirstName(){
        return 
    $this->firstname;

    PS - this is not really a design question, but a "how do I code this" question for the main PHP forum.
    Christopher

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2004
    Location
    Fort Lauderdale
    Posts
    522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    You misunderstood my question. I know how to code php. I needed advice on how to pass the id up the hiararchy of class. I know that now. I have another question here: ( php 4 )
    Code:
    <?php
    
    class User{
    
    var $userid;
    var $username;
    var $firstname;
    var $lastname;
    var $password;
    var $email;
    var $signupdate;
    var $lastlogin;
    var $city;
    var $state;
    var $zip;
    var $registrationstatus;
    var $activestatus;
    var $forumname;
    
    function User($userId){
    	$this->userid=$userId;
    }
    
    function getFirstName(){
    	return $this->firstname;
    }
    
    }//end class User
    
    //**********************************************
    
    class Trainer extends User{
    
    var $experience;
    var $trainerstyle;
    var $reasonfortraining;
    var $fieldofstudy;
    var $degree;
    var $yearsofexperience;
    var $certifications;
    var $educationalbackground;
    var $specialization;
    var $liabilityinsurance;
    var $cpr;
    
    function Trainer($id){
    	$this->User($id);//passing it to the parent constructor
    }
    
    }//end Trainer class
    ?>
    how do I fill the information in those classes. do I need to create another class that will fill out those values for me?
    when I code this:
    Code:
    $Trainer = new Trainer(34);
    $Trainer->getFirstName();
    $Trainer->getExperience();
    the classes are still empty so I get nothing....I need a way to fill out all the values . Should I include a function in teh trainer class that filles out the trainer values and user class that fills out user values in the user class?

    Help me out...

  4. #4
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function Trainer($id){
        
    $this->User($id);//passing it to the parent constructor

    This code should work correctly.
    the classes are still empty so I get nothing....I need a way to fill out all the values . Should I include a function in teh trainer class that filles out the trainer values and user class that fills out user values in the user class?
    Yes, set User properties with methods in User, and et Trainer properties with methods in Trainer.
    You misunderstood my question. I know how to code php. I needed advice on how to pass the id up the hiararchy of class. I know that now. I have another question here: ( php 4 )
    Again, these are "how to code it" questions that will get more responses in the main PHP forum.
    Christopher


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •