1

i have a definition like :

define('LIBRARIES_URI', get_template_directory_uri() . '/libraries/');

Now, i have an associative array like :

array( 'name' => 'superfish-css', 'path' => LIBRARIES_URI .'superfish/css/superfish.css', 'type' => 'style' )

However, path is not right, this gives me an error, because there is an expression i guess. I tried various things like double quotes and stuff, but i cannot seem to get it right without an external variable. Is there a way to correctly interpolate that ?

FULL EXAMPLE :

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


}
Spyros
  • 46,820
  • 25
  • 86
  • 129
  • What's the specific error that you are getting? –  Oct 16 '11 at 20:01
  • I don't see any error here ... – KingCrunch Oct 16 '11 at 20:01
  • Ummm, could you be a little bit more precise in what error you get? This works for me if I add `function get_remplate_directory_uri() {return '/var/www';}` to the top. – phihag Oct 16 '11 at 20:01
  • paste `get_template_directory_uri` please... – Dejan Marjanović Oct 16 '11 at 20:02
  • Surmising from the question, you are trying to declare a class property with an expression. That's not possible. Assign the attribute in the constructor. – mario Oct 16 '11 at 20:03
  • The error is "PHP Parse error: syntax error, unexpected '.', expecting ')'". Btw, this is actually an array of arrays. Like $array = (array(), array() ...). If i remove this line, the other arrays work fine, so this definitely is the one that causes the error. – Spyros Oct 16 '11 at 20:03
  • LIBRARIES_URI is definitely correct, it's been used extensively in other places. – Spyros Oct 16 '11 at 20:05
  • @mario, are you talking about this http://ideone.com/p88V0 ? – Dejan Marjanović Oct 16 '11 at 20:05
  • @SpyrosP Can you [upload](http://codepad.org) an example that demonstrates the problem? Come on, with 6k rep, you should now better than "it doesn't work" ;) – phihag Oct 16 '11 at 20:05
  • @SpyrosP, paste entire code, you probably have syntax error somewhere... should work. – Dejan Marjanović Oct 16 '11 at 20:06
  • possible duplicate of [Workaround for basic syntax not being parsed](http://stackoverflow.com/questions/2671928/workaround-for-basic-syntax-not-being-parsed) – mario Oct 16 '11 at 20:07
  • Status: Closed Reason: could not reproduce :) – Dejan Marjanović Oct 16 '11 at 20:32
  • @webarto: that's really really weird. The error i get seems to be about the '.', as i said before : PHP Parse error: syntax error, unexpected '.', expecting ')' – Spyros Oct 16 '11 at 20:37

1 Answers1

5

Class attribute declarations may not contain expressions, only literal/constant values.

Move your assignment into the constructor.

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
  • ah, interesting, so this why this is happening, i suppose i would have to use another variable then. Let me try it, i guess it's the only way. I probably will not avoid it. – Spyros Oct 16 '11 at 20:38
  • yeap, i ended up doing it in the constructor. Interesting differentiation. It works fine now. – Spyros Oct 16 '11 at 20:49