【发布时间】:2012-10-08 09:07:27
【问题描述】:
我有一个像下面这样的课程:
$structure = new stdClass();
$structure->template->view_data->method = 'get_sth';
$structure->template->view_data->lang = $lang;
$structure->template->view_data->id_page = $id_page;
$structure->template->view_data->media_type = 'ibs';
$structure->template->view_data->limit = '0';
$structure->template->view_data->result_type = 'result';
我很好奇它是否可以像下面这样写?
$structure->template->view_data->method = 'get_sth_else',
->lang = $lang,
->id_page = $id_page,
->media_type = 'ibs',
->limit = '0',
->result_type = 'result',
->another-data->method = 'sth_else',
->type = 'sth',
->different = 'sth sth';
【问题讨论】:
-
你不能使用你的语法,但是你可以在每个setter中返回
$this以便调用setA($a) -> setB($b) -> ... -> setZ($z)。 -
他们可以通过重载 __call 函数来重载 set* 函数来使其更容易。
标签: php codeigniter object fluent-interface