1

I am getting a parse error on the lines with the constant (DEPLOYMENT). Why is this now allowed, or am I missing something.

Parse error: parse error, expecting `')'' in

class UploadComponent extends Object {

    private $config = array(
        'accessKey' => 'XXXX',
        'secretKey' => 'XXXX',

        'images' => array(
            'bucket' => DEPLOYMENT.'-files/images',
            'dns' => false
        ),

        'files' => array(
            'bucket' => DEPLOYMENT.'-files/files',
            'dns' => false
        ),

        'assets' => array(
            'bucket' => DEPLOYMENT.'-files/assets',
            'dns' => false
        )
    );
    ....
}
4
  • (sidenote) You dont want to have the dependency on the global constant in there anyway. Commented Oct 14, 2010 at 11:21
  • where are you defining "DEPLOYMENT"? Commented Oct 14, 2010 at 11:21
  • @Gordon why not? @pleasedontbelong really? What is the point of your comment. Commented Oct 14, 2010 at 11:55
  • because dependencies ought to be injected. If you rely on outside state, your class can no longer be used in isolation. You cannot have this class without also having the global constant. That's bad for maintenance and testing. Commented Oct 14, 2010 at 12:24

2 Answers 2

7

You can't use variables when defining class vars. Initialize your array inside the constructor instead:

class UploadComponent extends Object {

    private $config;

    function __construct() {
        $this->config = array(
            'accessKey' => 'XXXX',
            'secretKey' => 'XXXX',

            'images' => array(
                'bucket' => DEPLOYMENT.'-files/images',
                'dns' => false
            ),

            'files' => array(
                'bucket' => DEPLOYMENT.'-files/files',
                'dns' => false
            ),

            'assets' => array(
                'bucket' => DEPLOYMENT.'-files/assets',
                'dns' => false
            )
        );
    }
}
Sign up to request clarification or add additional context in comments.

Comments

5

The reason is that 'constants' can be defined dynamically. Their contents are therefore only known at run-time, and not compile-time.

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.