require_once('***.class.php'); $class = new class_name();
<?php class test { public function ss() { return "Hello, World!"; } }$t = new test(); echo $t->ss(); ?> 最简单的例子!
//借用2楼的成果 class test { public function ss() { return "Hello, World!"; } } echo test :: ss();
进阶 <?php class test { private $num=0; public $a=0; public $b=0; public function test($a,$b){ $this->a=$a; $this->b=$b; } public function getsum() { return "This Sum is:".$this->_getnum(); } private function _getnum(){ $this->num = $this->a+$this->b; return $this->num; } }$t = new test(35,87); echo $t->getsum(); ?>
你麻不麻烦啊,直接getsum()返回和的值就得了。_getsum()多此一举。
应该多看看PHP手册!~ http://www.phpchina.com/
对象 对象初始化 要初始化一个对象,用 new 语句将对象实例到一个变量中。 <?php class foo { function do_foo() { echo "Doing foo."; } }$bar = new foo; $bar->do_foo(); ?> 这个是PHP手册上的
<?php class test { public function t() { echo 'OK'; } } //静态调用 test::t(); //动态调用 h=new test(); h->t(); ?>希望能帮到你!
$class = new class_name();
<?php
class test {
public function ss() {
return "Hello, World!";
}
}$t = new test();
echo $t->ss();
?>
最简单的例子!
//借用2楼的成果
class test {
public function ss() {
return "Hello, World!";
}
}
echo test :: ss();
<?php
class test {
private $num=0;
public $a=0;
public $b=0;
public function test($a,$b){
$this->a=$a;
$this->b=$b;
}
public function getsum() {
return "This Sum is:".$this->_getnum();
}
private function _getnum(){
$this->num = $this->a+$this->b;
return $this->num;
}
}$t = new test(35,87);
echo $t->getsum();
?>
http://www.phpchina.com/
对象初始化
要初始化一个对象,用 new 语句将对象实例到一个变量中。
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}$bar = new foo;
$bar->do_foo();
?> 这个是PHP手册上的
class test
{
public function t()
{
echo 'OK';
}
}
//静态调用
test::t();
//动态调用
h=new test();
h->t();
?>希望能帮到你!
test::t();
//动态调用
h=new test();
h->t();应改为:
//静态调用
test::t();
//动态调用
$h=new test();
$h->t();