<?php
//===============================================================================================
// Use the Planet class
//   require the 'planet.inc' class file
//   create an array that will hold many objects
//   instantiate many objects using new.  This will automatically call the __construct()
//   print the object, this will automatically call the __toString()
//   print the object from within this file instead of using the __toString()
//===============================================================================================
    require_once('planet.inc'); 

    $heading1 = Planet::$className;             //access the public static attribute 
    $heading2 = Planet::infoSolarSystem();      //call the static method 
                
    $mercury = new Planet("Mercury",  3100,    "36 million miles",    "88 days",  "59 days");
    $venus   = new Planet("Venus",    7700,    "67 million miles",   "225 days", "244 days");
    $earth   = new Planet("Earth",    7920,    "93 million miles","365.25 days", "24 hours");
    $mars    = new Planet("Mars",     4200,   "141 million miles",   "687 days", "24 hours, 24 min");
    $jupiter = new Planet("Jupiter", 88640,   "483 million miles", "11.9 years",  "9 hours, 50 min");
    $saturn  = new Planet("Saturn",  74500,   "886 million miles", "29.5 years", "10 hours, 39 min");
    $uranus  = new Planet("Uranus",  32000, "1.782 billion miles",   "84 years", "23 hours");
    $neptune = new Planet("Neptune", 31000, "2.793 billion miles",  "165 years", "15 hours, 48 min");
//  $pluto   = new Planet("Pluto",    1500, "3.670 billion miles",  "248 years",  "6 days, 7 hours");
        
    $earth->diameter = 7925;                    //private instance property. calls the __set() method 
//  print $earth->diameter;                     //private instance property. calls the __get() method

    $planets = array();
    $planets['Mercury'] = $mercury;             //building a keyed array of object
    $planets['Venus']   = $venus;
    $planets['Earth']   = $earth;
    $planets['Mars']    = $mars;
    $planets['Jupiter'] = $jupiter;
    $planets['Saturn']  = $saturn;
    $planets['Uranus']  = $uranus;
    $planets['Neptune'] = $neptune;

    $chosen = $_GET['planet'];                  //obtain the planet selected from dropdown list
    
    if (! $chosen) $chosen = 'Earth';           //if none is chosen, use Earth

    $thePlanet = $planets[$chosen];             //the object that was chosen 

    $selected = array();                        //array to hold which planet was selected
    $selected[$chosen] = 'selected';

    print "<HTML>
           <HEAD>
           <TITLE>Our Solar System</TITLE>
           <HEAD>
           <H1>Planet Object - $heading1 </H1>
           <HR>
           <H2>$heading2 </H2>
           <H3>Select a planet to view its planetary detail:</H3> 
           <FORM ID=frm1>
           <SELECT NAME='planet' onChange=document.getElementById('frm1').submit()>   
                <OPTION $selected[Mercury]>Mercury </OPTION>       
                <OPTION $selected[Venus]>  Venus   </OPTION> 
                <OPTION $selected[Earth]>  Earth   </OPTION> 
                <OPTION $selected[Mars]>   Mars    </OPTION> 
                <OPTION $selected[Jupiter]>Jupiter </OPTION> 
                <OPTION $selected[Saturn]> Saturn  </OPTION> 
                <OPTION $selected[Uranus]> Uranus  </OPTION> 
                <OPTION $selected[Neptune]>Neptune </OPTION> 
<!--            <OPTION $selected[Pluto]>  Pluto   </OPTION>  --> 
           </SELECT>
           <FORM>";

    print $thePlanet;                           //implicitly call the __toString() method

//  print $thePlanet->__toString();             //or explicitly call the __toString() method

//  $thePlanet->planetName = 'xxx';             //trying to set the planet name to 'xxx'
                                                //this will fail in the __set() method
    print "Total count of planets created: ";
    print Planet::getCountPlanets();            //call the static getter method

?>

<?php include "../include.php"; ?>              <!-- hyperlink to see the code -->