0

I know this is probably a newbie question, but is it possible to do this?

unserialize(LOG_ACTIONS_.''.strtoupper($language));

I have list of constants with _LANGUAGE which I want to use the variable $language with.

Example:

unserialize(LOG_ACTIONS_ENGLISH);

Here's the error I get:

Fatal error: Call to undefined function LOG_ACTIONS_strtoupper()

2 Answers 2

7

Use constant() to get the constant's actual value.

unserialize(constant(LOG_ACTIONS_.''.strtoupper($language)));

I'm not sure whether having serialized data in a constant is really wise, though - it can be expensive if there's a lot of data in them.

I assume it's to circumvent the restriction that constants can't contain array values. This SO question shows some better ways to work around that:

What is the most "elegant" way to define a global constant array in PHP

Sign up to request clarification or add additional context in comments.

Comments

1

You could probably just use the constant() function:

unserialize(constant('LOG_ACTIONS_'.strtoupper($language)));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.