<?php
class Hello {
private $content = "HelloMyPHP";
public $name;
public function getContent() {
return $this->content;
}
function __construct($name) {
$this->name = $name;
echo "__construct<br/>" . $this->name;
}
function __destruct() {
echo "<br/>__destruct<br/>byebye";
}
public function setContent($content) {
echo "<br/>setContent<br/>" . $content;
$this->content = $content;
}
function dangerous() {
try {
throw new Exception ( "<br/>就是想跑出异常罢了<br/>" );
} catch ( Exception $e ) {
echo $e->getMessage ();
}
}
}
$myHello = new Hello ( "myname" );
$myHello->setContent ( "我的内容" );
echo $myHello->getContent ();
echo $myHello->name;
$myHello->dangerous ();
?>