JPT62089
Sun 22nd May '05, 3:02am
I am learning how to use OOP atm and its very frustrating! I just recently got a book on PHP and I am following what it says
Here is class.demo.php:
<?php
class Demo {
public $name;
function hello() {
print " Hello $this->name!";
}
}
?>
testdemo.php:
<?php
require('class.demo.php');
$objDemo = new Demo();
$objDemo->name = 'Steve';
$objAnotherDemo = new Demo();
$objAnotherDemo->name = "Ed";
$objDemo->hello();
$objAnotherDemo->hello();
?>
error
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in c:\phpdev5\www\phplearn\class.demo.php on line 4
Fatal error: Cannot instantiate non-existent class: demo in c:\phpdev5\www\phplearn\testdemo.php on line 5
what did I do wrong? I checked and rechecked the code at least a dozen times! but it is exactly the same.... any ideas?
Here is class.demo.php:
<?php
class Demo {
public $name;
function hello() {
print " Hello $this->name!";
}
}
?>
testdemo.php:
<?php
require('class.demo.php');
$objDemo = new Demo();
$objDemo->name = 'Steve';
$objAnotherDemo = new Demo();
$objAnotherDemo->name = "Ed";
$objDemo->hello();
$objAnotherDemo->hello();
?>
error
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in c:\phpdev5\www\phplearn\class.demo.php on line 4
Fatal error: Cannot instantiate non-existent class: demo in c:\phpdev5\www\phplearn\testdemo.php on line 5
what did I do wrong? I checked and rechecked the code at least a dozen times! but it is exactly the same.... any ideas?