You are here

6 函数调用

admin 的头像
Submitted by admin on 星期五, 2015-09-18 08:47

作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

在函数调用中, 在操作符(=, <, >,等等)的两边应该各有一个空格,而在函数名和函数的开括号之间则没有空格。在函数的开括号和它的第一个参数之间也没有空格。中间的函数参数使用逗号和空格分隔,在最后一个参数和闭括号之间没有空格。在上面的例子中,区块内容的赋值语句就说明了这几点:

正确的

$block['content'] = theme('feed_icon', array('url' => 'rss.xml', 'title' => t('Syndicate')));

 

如果这样写就错误了

$block['content']=theme ('feed_icon',array('url'=>'rss.xml','title'=>t('Syndicate')));

 

 

这个规则也存在例外的情况。在一个包含多个相关赋值语句的代码块中,如果能够提高可读性,那么可以在赋值操作符周围插入多个空格(摘自node.moduletemplate_preprocess_node函数):

 

$variables['date']      = format_date($node->created);

$variables['name']      = theme('username', array('account' => $node));

 

$uri = entity_uri('node', $node);

$variables['node_url']  = url($uri['path'], $uri['options']);

$variables['title']     = check_plain($node->title);


Drupal版本: