Reputation: 13537
I have a function called getSources(); In this function I want to easily assign numbers to constants. I figured this would work:
const A = 1;
const B = 2;
const C = 3;
const D = 4;
And I could just do this:
$someValue = A;
But it doesn't work. What am I missing? I don't want these variables to be used outside of the scope of this function.
Upvotes: 0
Views: 103
Reputation: 79
you can do like this
function getSources()
{
define(A,1);
define(B,2);
....
}
like this you can solve it
Upvotes: 0
Reputation: 490413
You need to use the scope resolution operator (::
) to access them (if they're setup as const
for a class).
Otherwise, you need to use define()
which makes the identifiers global.
Upvotes: 0