简单的类:
<?php
//定义标准文件名:preson.class.php
// 类名的买个单词的首字母必须大写(严格的驼峰式写法)
//定义类:
class Preson{
//属性:
public $name='user1';
public $age=20;
public $sex='nan';
//方法:
function say(){
$num=100;
echo "my age is {$num}";
echo "hello word,my name is {$this->name}";
}
}
//类的实例化
$user1=new Preson();
//类方法的调用
$user1->say();
//类属性的调用
echo $user1->name;
?>
结果:
hello word,my name is user1
user1
网友评论