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

Spy*_*ros 1 php

我有一个定义:

define('LIBRARIES_URI', get_template_directory_uri() . '/libraries/');
Run Code Online (Sandbox Code Playgroud)

现在,我有一个关联数组,如:

array( 'name' => 'superfish-css', 'path' => LIBRARIES_URI .'superfish/css/superfish.css', 'type' => 'style' )
Run Code Online (Sandbox Code Playgroud)

但是,路径不对,这给了我一个错误,因为我猜有一个表达式.我尝试了各种各样的东西,如双引号和东西,但我似乎无法在没有外部变量的情况下做到正确.有没有办法正确插值?

完整示例:

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;
  }  


}
Run Code Online (Sandbox Code Playgroud)

mar*_*rio 5

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

将您的作业移动到构造函数中.