Re: Expand variable in comparison
| From: | Marcus | Date: | Sat, 19 Jan 2008 03:22:26 +0000 |
| Subject: | Re: Expand variable in comparison | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267617@lists.php.net to get a copy of this message | ||
Andrés Robinet wrote:
I do only have control over the content of this variable itself (Comes from $_REQUEST) - not over the code.-----Original Message----- From: news [mailto:news@ger.gmane.org] On Behalf Of Marcus Sent: Friday, January 18, 2008 9:56 PM To: php-general@lists.php.net Subject: [PHP] Re: Expand variable in comparison Andrés Robinet wrote:I don't understand what you are trying to do,For certain reason $this->var can only be set to a string and not to a variable! Any suggestions?-----Original Message----- From: news [mailto:news@ger.gmane.org] On Behalf Of Marcus Sent: Friday, January 18, 2008 4:51 PM To: php-general@lists.php.net Subject: [PHP] Expand variable in comparison Hi! Is there any way to get the following snippet returning a true? ... $this->var = ????? if ($this->var == $preDefinedStringToTestWith)Uh! Shouldn't it work? $this->var = $preDefinedStringToTestWithreturn true;elsefalse;The problem: I don't know, what $preDefinedStringToTestWith is! $this->var can be set to any string. I tried $this->var = "${preDefinedStringToTestWith}" but this doesn't get expanded.
but maybe you are trying to achieve something like: <?php class Test { var $var = ''; function Test() { $this->var = "theVariableName"; // Hold variable name $theVariableName = "whatever you want"; if (${$this->var} == $theVariableName)Nearly, but I can only alter the content of $var itself! I cannot change the comparison. Comparison is always if ($this->var == $preDefinedStringToTestWith)echo ${$this->var}." is equal to ".$theVariableName;elseecho "bad dog! stop it!";} } new Test(); ?>