English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
あるクラスにはいくつかのメソッドがあります。このクラスをインスタンス化してメソッドを呼び出す場合、一つずつ呼び出す必要があります。例えば:
db.php
<?php class db { public function where() { //code here } public function order() { //code here } public function limit() { //code here } }
index.php
<?php $db = new db(); $db->where(); $db->order(); $db->limit();
れんせいさくどうをかたちづけるためには、メソッドの終わりに return $this を追加する必要があります。
db.php
<?php class db { public function where() { //code here return $this; } public function order() { //code here return $this; } public function limit() { //code here return $this; } }
index.php
<?php $db = new db(); $db->where();->order();->limit();
以上のPHPのれんせいさくどうのりょうりせいかいを詳しく解説したのは、みなさまに参考にしていただければ幸いです。また、呐喊教程に対するご支援をどうぞよろしくお願いいたします。