wadkar
wadkar

Reputation: 960

Define constant in a different namespace php

Here's what I was doing in the past

//file: bar.php
defined('MYC') or define('MYC', 'val1');
//file: bootstrap.php
define('MYC', 'val2');

I would include bootstrap.php first which would set MYC = 'val2'.
Now bar.php is in the \Foo\Bar namespace, i.e. to say

//file: bar.php
namespace Foo\Bar;
defined('MYC') or define('MYC', 'val1');
//file: bootstrap.php
//following doesn't work
//const \Foo\Bar\MYC = 'val2';
//?? what do I do here ??

Upvotes: 0

Views: 2555

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190956

Just define the key to have the namespace in the name.

Upvotes: 1

Related Questions