I made up a silly example to learn OOP.
I can’t get the object that I passed into another object to work…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>User Registration Form</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="styles/index.css">
</head>
<body>
<h1>What kind of soup would you like today?</h1>
<form method="post" action="results.php"> <!-- ACTION -->
<!-- Menu Choices -->
<div>
<label>I'm not sure...</label>
<input type="radio" name="soup" value="unsure" class="radio" /><br />
<label>Broccoli:</label>
<input type="radio" name="soup" value="Broccoli" class="radio" /><br />
<label>Tomato:</label>
<input type="radio" name="soup" value="Tomato" class="radio" checked="yes" /><br />
<label>Chicken:</label>
<input type="radio" name="soup" value="Chicken" class="radio" /><br />
<label>Split Pea:</label>
<input type="radio" name="soup" value="Split Pea" class="radio" /><br />
</div>
<!-- Submit button -->
<div>
<input type="submit" name="btnSubmit" value="Place Order" class="btn" id="btnSubmit" />
</div>
</form>
</body>
</html>
<?php
include ('classes/Soup.class.php');
$objSoup = new Soup($_POST['soup']);
echo $objSoup->getSoupType();
$objBowl = new Bowl();
$objBowl->fillBowl($objSoup);
echo "The bowl contains " . $objBowl->getBowlContents() . "soup in it.";
?>
<?php
class Soup{
private $type;
public function __construct($t=null){
$this->type = $t;
}
public function getSoupType(){
switch ($this->type){
case "unsure":
return "No soup for you!!";
break;
default:
return "You chose " . $this->type . " soup.";
break;
}
}
}
class Bowl{
private $contents;
public function fillBowl(Soup $s){
$this->contents = $s;
}
public function getBowlContents(){
if (is_null([B]$this->contents.type[/B])) {
return "The bowl is empty!";
} else {
return "The bowl contains " . [B]$this->contents.type[/B] . " soup!";
}
}
}
The areas in BOLD seem to be the issue…
TomTees