开发者

Concatenation of php class static variables

开发者 https://www.devze.com 2023-01-08 22:40 出处:网络
My first class: <?php require_once( \'error/DisconnectedHandler.php\' ); require_once( \'error/NoSuchRequestHandler.php\' );

My first class:

<?php
  require_once( 'error/DisconnectedHandler.php' );
  require_once( 'error/NoSuchRequestHandler.php' );

  class NetworkManager {

  public static final $RESPONSE_JUMP = 1000;
  ....

My second class:

<?php
    require_once( '../NetworkManager.php' );

    class DisconnectedHandler implements Handler{
        public static $TYPE          = 2000;
        public static $RESPONSE_TYPE = self::$TYPE + NetworkManager::$RESPONSE_JUMP;
        public static $VER           = 0;

I get an error in this line:

public static $RESPONSE_TYPE = self::$TYPE + NetworkManager::$RESPONSE_JUMP;

Eclipse IDE paint $TYPE in red and says:

Multiple annotations f开发者_StackOverflowound at this line:
- syntax error, unexpected '$TYPE', expecting 
 'identifier'
- syntax error, unexpected '$TYPE', expecting 
 'identifier'

What is the correct syntax for that?


Static variable declarations (as well as class constants) must be literally defined and cannot contain expression as they are evaluated prior to runtime.

You have to initialize your DisconnectedHandler::$RESPONE_TYPE in a constructor or more likely in a static initializer method.

0

精彩评论

暂无评论...
验证码 换一张
取 消