首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关联数组中表达式的字符串插值

关联数组中表达式的字符串插值
EN

Stack Overflow用户
提问于 2011-10-17 03:58:48
回答 1查看 471关注 0票数 1

我有这样的定义:

代码语言:javascript
复制
define('LIBRARIES_URI', get_template_directory_uri() . '/libraries/');

现在,我有一个像这样的关联数组:

代码语言:javascript
复制
array( 'name' => 'superfish-css', 'path' => LIBRARIES_URI .'superfish/css/superfish.css', 'type' => 'style' )

然而,path是不正确的,这给了我一个错误,因为我猜有一个表达式。我尝试了各种方法,比如双引号和其他东西,但如果没有外部变量,我似乎无法正确完成。有没有一种方法可以正确地对其进行插值?

完整示例:

代码语言:javascript
复制
define('LIBRARIES_PATH', TEMPLATEPATH . '/libraries/');


class Kosmos
{

  private static $inclusions = array(

    array( 'name' => 'style.css', 'path' => "get_bloginfo('stylesheet_url')", 'type' => 'style' ),
    array( 'name' => 'jquery', 'path' => '', 'type' => 'script' ),
    array( 'name' => 'jquery-ui-core', 'path' => '', 'type' => 'script' ),
    array( 'name' => 'jquery-ui-tabs', 'path' => '', 'type' => 'script' ),
    array( 'name' => 'superfish-css', 'path' => LIBRARIES_URI .'superfish/css/superfish.css', 'type' => 'style' ),
    array( 'name' => 'superfish-js', 'path' => "LIBRARIES_URI . 'superfish/js/superfish.js'", 'type' => 'script', 'dep' => array('jquery') ),
    array( 'name' => 'superfish-hover', 'path' => "LIBRARIES_URI . 'superfish/js/hoverIntent.js'", 'type' => 'script', 'dep' => array('jquery') ),
    array( 'name' => 'jquery-color', 'path' => "LIBRARIES_URI . 'horizontalMenu/jquery.color-RGBa-patch.js'", 'type' => 'script' ),

    /* admin */

    array( 'name' => 'admin-css', 'path' => "ADMIN_CSS_URI . 'admin.css'", 'type' => 'admin-style' ),
    array( 'name' => 'tabs-js', 'path' => "LIBRARIES_URI . 'tabs/tabs.js'", 'type' => 'admin-script' )

  );

  private static $admin_inclusions = array();

  public function inclusions() {
    return self::$inclusions;
  }

  public function admin_inclusions() {
    return self::$admin_inclusions;
  }  


}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-17 04:38:00

类属性声明可以不包含表达式,只能包含文字/常量值。

将赋值移动到构造函数中。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7786902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档