tags:

views:

37

answers:

1

In PHP is it possible to have constants with local scope? Is yes please provide a small example.

+6  A: 

Yes, but only using a class.

class Foo
{
    const BAR = 'hello, world';
}
print Foo::BAR;

About Kalium's comment, if you're on PHP 5.3, you can indeed also use namespaces:

namespace Foo;
const BAR = 1;
Macmade
May also work with namespacing.
Kalium