seppzzz
seppzzz

Reputation: 229

Silverstripe 3.4 define and public static

In Silverstripe 3.4 i get an Error

'Parse error: syntax error, unexpected '.', expecting ',' or ';' in /Applications/MAMP/htdocs/Silverstripe/myModule/code/Page.php on line 10'

_config.php:

define('THIS_MODULE_DIR',  basename(dirname(__FILE__)));

Page.php:

public static $icon = THIS_MODULE_DIR.'/img/contact-file.gif';  // line 10

Please explain why this error occurs / what's i am doing wrong.

Upvotes: 0

Views: 47

Answers (1)

user3477804
user3477804

Reputation:

PHP before 5.6 doesn't allow expressions for default values. You could use

public static $icon = 'my-folder/img/contact-file.gif';

But that requires the folder to have a specific name.

You could also set the value in the same file as class, but after the deceleration

<?php

class Foo {
  public static $icon;
}

Foo::$icon = THIS_MODULE_DIR.'/img/contact-file.gif';

The best alternative though is to upgrade to at least PHP 5.6, especially no earlier version is supported any more.

Upvotes: 1

Related Questions