0

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 found at this line:
- syntax error, unexpected '$TYPE', expecting 
 'identifier'
- syntax error, unexpected '$TYPE', expecting 
 'identifier'

What is the correct syntax for that?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.