I encountered a problem when using PHP chain calls:
There is a class "Site" below:
<?php
class Site{
public function api(){
require('class.Api.php');
$this->api = new Api();
return $this->api;
}
}
?>
There is also a class "Api" located in "class.Api.php":
<?php
class Api{
public function auth(){
//quiet a few
}
public function render(){
//quiet a few
}
}
?>
Use the following code to instantiate:
$site = new Site();
Call the following code again:
$site->api()->auth();
$site->api()->render();
Will PHP repeat require() and create new object API? If so, require() can be replaced by require_once(), but how to make "$site->api()" return the same object? Thanks!
Single case mode.
It’s just a simple writing, but it still needs a lot of optimization.