Here's the full code of my document:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="Php testing. " />
<meta name="keywords" content="phptesting" />
<meta name="author" content="Noah Lowenthal" />
<title>Age of Sorcery</title>
</head>
<body>
<?php // AoS.php
echo "Welcome to The Age of Scorcery.<br />";
global $dummyhealth;
$dummyhealth = 500;
class Bow
{
public $arrows;
public $drawn;
public $shot;
public $dummyhealth;
function __construct()
{
$this->arrows = "50";
$this->drawn = "false";
}
function draw()
{
echo "The bow has been drawn.<\br>";
$this->drawn = "true";
}
}
class Wooden_Bow extends Bow
{
public $attack;
function __construct()
{
parent::__construct();
$this->$attack = 40;
}
function shoot()
{
echo "The wooden bow has been shot.<\br>";
$this->drawn = "false";
$this->shot = "true";
$dummyhealth -= $attack;
}
}
class Silver_Bow extends Bow
{
public $attack;
function __construct()
{
parent::__construct();
$this->$attack = 60;
}
function shoot()
{
echo "The gold bow has been shot.<\br>";
$this->drawn = "false";
$this->shot = "true";
$dummyhealth -= $attack;
}
}
class Gold_Bow extends Bow
{
public $attack;
function __construct()
{
parent::__construct();
$this->$attack = 80;
}
function shoot()
{
echo "The gold bow has been shot.<\br>";
$this->drawn = "false";
$this->shot = "true";
$dummyhealth -= $attack;
}
}
echo $dummyhealth;
$mygoldbow = new Gold_Bow;
echo "Ready! <\br>";
$mygoldbow->draw();
$mygoldbow->shoot();
echo $dummyhealth;
?>
</body>
</html>
I keep getting a "Notice: Undefined variable: attack in C:\web\AoS.php on line 76
Fatal error: Cannot access empty property in C:\web\AoS.php on line 76" error whenever I run it.
I'm sorry if this is a really trivial error, but I can't seem to find what I did wrong.
I'd really appreciate help.
Thanks,
Noah


Sign In
Create Account

Back to top









