随便举个简单例子就行了!
14 个解决方案
#1
require_once('***.class.php');
$class = new class_name();
$class = new class_name();
#2
<?php
class test {
public function ss() {
return "Hello, World!";
}
}
$t = new test();
echo $t->ss();
?>
最简单的例子!
#3
//借用2楼的成果
class test {
public function ss() {
return "Hello, World!";
}
}
echo test :: ss();
#4
进阶
<?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();
?>
<?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();
?>
#5
+
#6
+2
#7
????
#8
你麻不麻烦啊,直接getsum()返回和的值就得了。_getsum()多此一举。
#9
应该多看看PHP手册!~
http://www.phpchina.com/
http://www.phpchina.com/
#10
对象
对象初始化
要初始化一个对象,用 new 语句将对象实例到一个变量中。
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
这个是PHP手册上的。。。
#11
~~~~~~~~~~~~~~~~~~
#12
你是没有明白意思...他是想演示 类的内部方法调用...
#13
<?php
class test
{
public function t()
{
echo 'OK';
}
}
//静态调用
test::t();
//动态调用
h=new test();
h->t();
?>
希望能帮到你!
class test
{
public function t()
{
echo 'OK';
}
}
//静态调用
test::t();
//动态调用
h=new test();
h->t();
?>
希望能帮到你!
#14
//静态调用
test::t();
//动态调用
h=new test();
h->t();
应改为:
//静态调用
test::t();
//动态调用
$h=new test();
$h->t();
test::t();
//动态调用
h=new test();
h->t();
应改为:
//静态调用
test::t();
//动态调用
$h=new test();
$h->t();
#1
require_once('***.class.php');
$class = new class_name();
$class = new class_name();
#2
<?php
class test {
public function ss() {
return "Hello, World!";
}
}
$t = new test();
echo $t->ss();
?>
最简单的例子!
#3
//借用2楼的成果
class test {
public function ss() {
return "Hello, World!";
}
}
echo test :: ss();
#4
进阶
<?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();
?>
<?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();
?>
#5
+
#6
+2
#7
????
#8
你麻不麻烦啊,直接getsum()返回和的值就得了。_getsum()多此一举。
#9
应该多看看PHP手册!~
http://www.phpchina.com/
http://www.phpchina.com/
#10
对象
对象初始化
要初始化一个对象,用 new 语句将对象实例到一个变量中。
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
这个是PHP手册上的。。。
#11
~~~~~~~~~~~~~~~~~~
#12
你是没有明白意思...他是想演示 类的内部方法调用...
#13
<?php
class test
{
public function t()
{
echo 'OK';
}
}
//静态调用
test::t();
//动态调用
h=new test();
h->t();
?>
希望能帮到你!
class test
{
public function t()
{
echo 'OK';
}
}
//静态调用
test::t();
//动态调用
h=new test();
h->t();
?>
希望能帮到你!
#14
//静态调用
test::t();
//动态调用
h=new test();
h->t();
应改为:
//静态调用
test::t();
//动态调用
$h=new test();
$h->t();
test::t();
//动态调用
h=new test();
h->t();
应改为:
//静态调用
test::t();
//动态调用
$h=new test();
$h->t();