views:

47

answers:

2

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
        )
    );
    ....
}
+7  A: 

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
            )
        );
    }
}
Tatu Ulmanen
+4  A: 

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

Evert