0

I try to access a constant in a class:

file1.php

[...]    
define('SUBDOMAIN','name');
require_once 'file2.php';
[...]

file2.php

[...]
class Gdl_Ute extends Response_Model {    
public $table = SUBDOMAIN.'zi_utp';

public function statuses()
{
[...]

I've used some variants like:

public function __construct()
{
self::$table = SUBDOMAIN.'zi_utp';
}

But there is always an error like:

PHP Parse error:  syntax error, unexpected '.', expecting ',' or ';'

or

syntax error, unexpected T_VARIABLE

Thanks very much for any hints! I've also read other similar questions on stackoverflow, but none has answered this problem correctly :/

UPDATE Now I've test the following solutions:

file2.php

public $table;
public function __construct()
{
self::$table = SUBDOMAIN.'zi_utp';
}

OR

file1.php

define('SUBDOMAIN',$subdomain);
const SUBDOMAIN = $subdomain;

RESULT

Access to undeclared static property OR
syntax error, unexpected T_VARIABLE
user1756209
  • 573
  • 10
  • 23
  • You can only initialize variables to scalar values (or arrays). If you just declare `public $table` then initialize in the constructor it should work. – elclanrs Aug 20 '13 at 22:59

1 Answers1

0

Use const to define your constant. have a look here

S.Thiongane
  • 6,883
  • 3
  • 37
  • 52