English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP로 연속 작업의 원리를 상세히 설명

한 클래스에 여러 메서드가 있을 때, 이 클래스를 인스턴스화하고 메서드를 호출할 때마다 하나씩 호출해야 합니다. 예를 들어:

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 구현 연속 작업 원리 설명은 저가 모두 공유한 내용입니다. 여러분에게 참고가 되길 바랍니다. 또한, 노래教程에 많은 지원을 부탁드립니다.

당신이 좋아할 만한 것