Re: Expand variable in comparison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrés Robinet wrote:
-----Original Message-----
From: news [mailto:news@xxxxxxxxxxxxx] On Behalf Of Marcus
Sent: Friday, January 18, 2008 9:56 PM
To: php-general@xxxxxxxxxxxxx
Subject:  Re: Expand variable in comparison

Andrés Robinet wrote:
-----Original Message-----
From: news [mailto:news@xxxxxxxxxxxxx] On Behalf Of Marcus
Sent: Friday, January 18, 2008 4:51 PM
To: php-general@xxxxxxxxxxxxx
Subject:  Expand variable in comparison

Hi!


Is there any way to get the following snippet returning a true?


...
$this->var = ?????
if ($this->var == $preDefinedStringToTestWith)
     return true;
else
     false;



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.

Uh! Shouldn't it work?

$this->var = $preDefinedStringToTestWith
For certain reason $this->var can only be set to a string and not to a
variable!

Any suggestions?

I don't understand what you are trying to do,

I do only have control over the content of this variable itself (Comes from $_REQUEST) - not over the code.



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)
		      echo ${$this->var}." is equal to ".$theVariableName;
		else
		      echo "bad dog! stop it!";
	}
}

new Test();
?>

Nearly, but I can only alter the content of $var itself!
I cannot change the comparison.
Comparison is always
if ($this->var == $preDefinedStringToTestWith)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux