您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 恩施分类信息网,免费分类信息发布

实例化php类的时候如何传参

2024/5/9 21:16:45发布3次查看
欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入 当我们实例化一个php类的时候,要怎么传递参数呢?这取决于该类的构造方法。 例: person.class.php ?php class person{ var $name; var $color; var $sex; var $age; function __construct($name,$
欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入
当我们实例化一个php类的时候,要怎么传递参数呢?这取决于该类的构造方法。
例:
person.class.php
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
xinxi();//cuihua is girl and age is 25 fuse is yello
$son->name = '田妞';
$son->eat();//田妞要吃饭
?>
恩施分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录