新建文件夹classes,在内部新建两个PHP文件:
1.Hello.php;
2.index.php;
在Hello.php中新建两个类1.Hello;2.Desktop;
<?php
class Hello{
public function sayHello(){
echo "hello<br>";
}
}
class Desktop{
public function Work(){
echo "work<br>";
}
}
在index.php中引导Hello.php文件,并实例化两个对象:
1.$b;
2.$d;
<?php
require_once 'Hello.php';
$b = new Hello();
$b->sayHello();
$d = new Desktop();
$d->Work();
网友评论