Home > Backend Development > PHP Tutorial > PHP ,这是什么意思? $ctrl->$action ();该如何处理

PHP ,这是什么意思? $ctrl->$action ();该如何处理

WBOY
Release: 2016-06-13 12:02:46
Original
810 people have browsed it

PHP ,这是什么意思? $ctrl->$action ();
$ctrl->$action ();

$ctrl 是一个对象,访问这个是什么东西?
--------------------------------------------------------------
访问属性 是这样的 $ctrl->action;
访问类方法 是这样的 $ctrl->action();

------解决方案--------------------
$ctrl->$action ();  也是调用一个方法名,只是这个方法的名字是用一个变量$action来代替
------解决方案--------------------
function fn() {
    echo 1;
}

$fn = 'fn';
$fn();

无非就是把函数或对象方法名变量化了 套进去照样运行
但这样使用前,建议用function_exist和method_exist检查

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template