0

Is there a standard way to make constants defined using the use constant pragma available to all of the packages that are use'd from an executed file?

Or even better, to make the constants defined in a package available to other packages that use that package? It seems like anything defined using use constant is only available in the scope of a single package (and is even unavailable to OO packages that use @ISA to inherit another package).

That means having to declare certain constants multiple times. Which kind of defeats the purpose of these constants.

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by lordspace
0

You may would like to try

our $MY_VARIABLE_AS_CONSTANT;

this variable should be available in all the packages.

the other option is to have a package that exports functions in main:: namespace.

Svet

0

You may would like to try

our $MY_VARIABLE_AS_CONSTANT;

That's pretty much what I ended up doing; I like the 'keyword' appearance of constants though.

like STATUS_ERROR instead of $STATUS_ERROR :lol:

the other option is to have a package that exports functions in main:: namespace.

I tried something similar; to have a package that returns the STATUS_ERROR constant from a get_error_status() function, and check it with an is_error_status($) function.

That got hella convuluted after a while.

0

if you use a package and not an object from the class you should write SomePackage::method ...

you may also have a package that acts as a container

e.g.

Package Status

$ref = Status::getInstance();
Status::getLastError();

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.