Richland College Multimedia Learning Center

Digital Media Programming with PHP and MySQL
Updated 1/7/2020 at 6:40pm

Homework #7: Objects


  1. Remember to follow all the standard Homework Requirements.

  2. This assignment will demonstrate:
    • Making a custom object in an "include" file
    • Using the custom object in a Web page

  3. In a separate PHP file, code the class definition for a "Car" object. Name this file something like carClass.php. Make sure your "Car" class has these features:
    • A constructor function that sets a default car model of "Edsel", and a default color of "bubblegum".
    • A function setModel( ) that allows the programmer to change the car's model.
    • A function getModel( ) that allows the programmer to retrieve (get) the car's model.
    • A function setColor( ) that allows the programmer to change the car's color.
    • A function getColor( ) that allows the programmer to retrieve (get) the car's color.
    This separate PHP file will be used as an "include" file in the PHP action page (see step 6, below).

  4. Make an "About Us" page for your class Web site. Name it aboutus.php.

  5. Put an HTML form on your About Us page, which allows the user to pick a car model and color. This means that you will have two items that the user can enter or select:
    1. Model
    2. Color
    The "model" and "color" choices can be text entry boxes, or radio buttons, or select lists; this is your option and your choice.

  6. Also put the action code into your About Us page.

  7. You will need to "include" the PHP "Car" class page that you made in step 3, in your About Us page.

  8. If the form has NOT been submitted yet, in the action code in the About Us page create a "Car" object. Don't put any arguments in the Car() function call when you create your instance of the "Car" class/object.

  9. If the form HAS been submitted (meaning that the user has selected or entered a new model and color for their car and has clicked the submit button), create a "Car" object and use the FORM values that the user selected or entered as the arguments in the Car() function call when you create your instance of the "Car" class/object. (Alternatively, you could create the "Car" object with no arguments, but then use the object's "Set" methods to change the model and color.)

  10. Immediately after you create the "Car" object in both cases given above, display the object's model and color properties in your About Us page. Use the "get" functions to retrieve these values.

  11. Upload your pages to your class Web site server.

  12. Test your page by clicking your student number on the "Student Sites" page of this class site. Display your About Us page. Test the form and "Car" code.

  13. HINT:
    1. You can have more than one default parameter in the constructor function. You need to separate multiple parameters with commas.