例:
person.class.php
<?php class person{ var $name; var $color; var $sex; var $age; function __construct($name,$age='',$sex='boy'){ $this->name = $name; $this->age = $age; $this->sex = $sex; $this->color = 'yello'; } function eat(){ echo $this->name.'要吃饭'; } function xinxi(){ echo $this->name.' is '.$this->sex.' and age is '.$this->age.' fuse is '.$this->color; } } ?>
son.php
<?php include('person.class.php'); $son = new person('cuihua',25,'girl');//此处的参数传递要和类的构造方法里面的参数顺序对应 //$son->xinxi();//cuihua is girl and age is 25 fuse is yello $son->name = '田妞'; $son->eat();//田妞要吃饭 ?>
如对本文有疑问, 点击进行留言回复!!
如何去设计前端框架能力?星巴克消息开放项目从0到1,从点到面的思考
PHP制作日历,实现在1970年到2020年之间的任何一个月份的输出。上半部分
网友评论