dongxing7083 2016-09-29 05:12
浏览 69

Silverstripe 3.4定义和公共静态

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.

  • 写回答

1条回答 默认 最新

  • donglong9745 2016-09-29 09:52
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类