Home  >  Article  >  Backend Development  >  slim - php is_callable()参数里有方括号?

slim - php is_callable()参数里有方括号?

WBOY
WBOYOriginal
2016-06-06 20:17:021163browse

看slim源码的时候发现这种用法

slim - php is_callable()参数里有方括号?
官方手册

slim - php is_callable()参数里有方括号?
为什么能这么用,$route是一个对象,$setOutputBuffering是里面一个方法

================
PS:还有这个是什么高级用法

slim - php is_callable()参数里有方括号?

回复内容:

看slim源码的时候发现这种用法

slim - php is_callable()参数里有方括号?
官方手册

slim - php is_callable()参数里有方括号?
为什么能这么用,$route是一个对象,$setOutputBuffering是里面一个方法

================
PS:还有这个是什么高级用法

slim - php is_callable()参数里有方括号?

首先,[...] 方括号是php5.4后提供的一个数组短写语法,其实就是和array(...)效果是一样的。

其次,callablephp表示可执行方法,callable的表示有很多种方式,利用数组来表示就是其中一种。这里的[$route, 'setOutputBuffering']就是表示$route这个对象中的setOutputBuffering这个方法。

最后的语法是php中的HEREDOC语法,其实就是一种多行字符串的表示方法。

[$route, 'setOutputBuffering']这种常用在call_user_func_array

Statement:
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