<?php
  
if (isset($_GET['source'])) {
        
highlight_file($_SERVER['SCRIPT_FILENAME']);
        exit;
  }
?>
<html>
<head>
<title>Object Oriented PHP</title>
    
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="theme-color" content="#B5C7DD" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../css/reset.css">
        <link rel="stylesheet" href="../css/mandy.css">
        <link rel="stylesheet" href="../css/form.css">

<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
</head>
<body>
    
<h2 class="pad-top">    
    
<?php   # need this to be able to view source in the below anchor tag
  
$urlPath=dirname($_SERVER['SCRIPT_URL']).'/'
  
$labsPath=$urlPath.'labs/'
?>     

    <a href="../index.php">CS 130A</a> → Lab 9
<a href="<?=$urlPath?>index.php?source" target="labs">Source code</a>

</h2>   


<h4>Working with Objects - Classes of Fruits</h4>
    <p class="nudge in">A program with 2 php classes each with >= 2 instantiations each.</p>

    
<!--<pre>-->

<?php   

//  classes
class Fruit
    
{
//    public $name;
//    public $color;
//    public $width;
////    public $skin="";
//    private $taste;

    
public function __construct($name$color$width$taste)
        {
        
$this->name $name;
//        echo $this->name; echo "<br>i am here <br>";
//        echo $name; echo "<br>i am here <br>";

        
$this->color $color;
        
$this->width $width;
        
$this->taste $taste;
        }    
    
    public function 
describeFruit()
        {
        
printf ("This %s fruit is a %s. <br> It is %d inches wide and tastes %s.<br>"$this->color$this->name$this->width$this->taste);
        }
        
    }
    
   
$apple = new Fruit("Mystery Fruit""red"3"crisp");
$apple->describeFruit();
   
$banana = new Fruit("banana""yellow"5"soft");
$banana->describeFruit();
   
echo 
$banana->color; echo "<br>";


class 
Dog
    
{
    public function 
__construct($name$color$weight$breed)
        {
        
$this->name $name;
//        echo $this->name; echo "<br>i am here <br>";
//        echo $name; echo "<br>i am here <br>";

        
$this->color $color;
        
$this->weight $weight;
        
$this->breed $breed;
        }    
    
    public function 
describeDog()
        {
        
printf ("%s is a %s %s and is %d pounds. <br>"$this->name$this->color$this->breed$this->weight);
        }
        
    }
    
   
$cloud = new Dog("Cloudy""white"7"Bichon Frise");
$cloud->describeDog();
   
$julie = new Dog("Julie""extra fluffy"22"Golden Retriever");
$julie->describeDog();
   
   
$dog $julie;
$fruit $banana;
   
   
print 
"<p>$dog->name is eating a $fruit->taste $fruit->name.<p>";
    
    
    
    
    
// giving up on default assignment    
////  classes
//class id
//    {
//    int(11);
//    }
//    
//class string
//    {
//    varchar(50);
//    }
//    
//class char
//    {
//    varchar(1);
//    }
//    
////  defining null variables
//    # student
//$s_id = "00000000000";
//$s_last = "NULL";
//$s_first = "NULL";
//$s_mi = "";
//   
//$s_address = "";
//$s_city = "";
//$s_state = "";
//$s_zip = "";
//
//$s_phone = "";
//$s_class = "";
//$s_dob = "";
//$s_pin = "";
//$f_id = "00000000000";
//    
//   # faculty
//$f_id = "00000000000";
//$f_last = "NULL";
//$f_first = "NULL";
//$f_mi = "";
//$loc_id = "00000000000";
//$f_phone = "";
//$f_rank = "";
//$f_pin = "00000000000";
//$f_image = "";
//    
    
    
    
    
?>     


    


<!--</pre>   -->

    
    <p class="hide">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
</p>

    <div class="stretch"></div>
</body>
</html>