Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Steve the Canuck
March 7, 2009, 6:44 am
rate this thread
I have a class with a bunch of constants in it, eg:
I want to store the name of the constant in a lookup file and then
obtain the value of the constant by referring to the constant defined
in the class. ie:, something like:
$encValue = getParameter('encValue); // this would return ENC_SSL
$encryption = Swift_Connection_SMTP::$encValue;
The above of course does not work. I've also tried variations like
changing the value of $encValue to 'Swift_Connection_SMTP::ENC_SSL',
but I can't figure out the right syntax to use in this case.
If nothing else works, of course, I can do something like:
if($encValue == 'ENC_SSL)
$encryption = Swift_Connection_SMTP::ENC_SSL
However, if possible, I'd like to be able to reference the constant
value based on the value in my configuration file.
Can anyone help?
Re: Variable value referencing the name of a constant?
echo constant($className . '::' . $constVarName);
You have a syntax error here. You probably want a second apostrophe
to enclose 'ENC_SSL', unless ENC_SSL is a defined constant.
And another syntax error here. Don't forget to terminate statements
If making your config file a PHP script isn't viable, you might want
to internalize parsing the file within your connection class, or
perhaps a dedicated config class.
PHP actually has a built-in function for parsing INI files, if you
think they might be useful:
$email = str_replace('sig.invalid', 'gmail.com', $from);