如何编写PHP7的扩展类?
- 内容介绍
- 文章标签
- 相关推荐
本文共计565个文字,预计阅读时间需要3分钟。
在PHP7中,有许多扩展类可以创建。今天,我们以`Person`类为例,实现`doing`方法和`saying`方法。以下是一个简单的示例:
1. 需要实现的细节: - 实现一个`Person`类 - 实现一个`doing`方法 - 实现一个`saying`方法
phpclass Person { public $name;
public function __construct($name) { $this->name=$name; }
public function doing($activity) { return {$this->name} is doing {$activity}.; }
public function saying($sentence) { return {$this->name} is saying: {$sentence}.; }}
// 使用示例$person=new Person(Alice);echo $person->doing(eating);echo $person->saying(Hello, world!);
在php7中,有许许多多的扩展类,今天我们就以person类为例实现doing方法和saying方法,有需要的小伙伴可以参考一下。
本文共计565个文字,预计阅读时间需要3分钟。
在PHP7中,有许多扩展类可以创建。今天,我们以`Person`类为例,实现`doing`方法和`saying`方法。以下是一个简单的示例:
1. 需要实现的细节: - 实现一个`Person`类 - 实现一个`doing`方法 - 实现一个`saying`方法
phpclass Person { public $name;
public function __construct($name) { $this->name=$name; }
public function doing($activity) { return {$this->name} is doing {$activity}.; }
public function saying($sentence) { return {$this->name} is saying: {$sentence}.; }}
// 使用示例$person=new Person(Alice);echo $person->doing(eating);echo $person->saying(Hello, world!);
在php7中,有许许多多的扩展类,今天我们就以person类为例实现doing方法和saying方法,有需要的小伙伴可以参考一下。

