class.Demo.php
Code:
<?php
class Demo {
private $_name;
public function sayHello() {
print "Hello ($this -> getName()}!";
}
public function getName () {
return $this -> _name;
}
public function setName($name) {
if (!is_string($name) || strlen($name) == 0) {
throw new Exception ("Invalid name value");
}
$this -> _name = $name;
}
}
?>
testdemo.php
Code:
<?php
require_once('class.Demo.php');
$objDemo = new Demo();
$objDemo->name = 'Steve';
$objDemo ->sayHello();
$objDemo -> setName(37); //would trigger an error
?>
i tried to type exactly the same code as in the Book.
when i open test.demo.php in the browser..it does not work.
is there any problems with codes.
thanx in advance !