PDA

View Full Version : gosh darned oop and php book


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?

Marco van Herwaarden
Sun 22nd May '05, 5:34am
Change:
public $name;
into:
var $name;

deVillefort
Tue 24th May '05, 11:29am
You must be reading a book on PHP5 and testing on PHP4... There are
some differences between 4 and 5's OOP. You can read up on PHP4's
here (http://www.php.net/manual/en/language.oop.php).