Re: Using constructs like unset() in expressions like ()&&()

From: Date: Sat, 18 Dec 2004 00:03:29 +0000
Subject: Re: Using constructs like unset() in expressions like ()&&()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204637@lists.php.net to get a copy of this message
Richard Lynch wrote:
Perhaps something like this: function my_unset($var){ global $$var; $wasset = isset($$var); unset($$var); return $wasset; } my_unset(‘a‘); //unset($a); Or, in a more general way: function forcereturn ($php){ return eval($php); } Damned if I understand *why* you want this, mind you. :-)
Thank you, Richard. That's what I am looking for. Your first solution may not be usable, because the variable to unset may not be a global variable. The second solution (that using eval()) may have a bug, because the unset() is called in a local-scope of the function forcereturn() (and so the variable "unset()"ted differs from the variable that we really want to unset()). However, there can be used eval() instead of forcereturn(): <?php (True==False) or (eval('unset($a);')); ?> Nevertheless, this solution has defects for general use: A lot of expressions with no return value can't be called with eval() (e.g. eval('break;') is not a good idea). However I don't say I need to use a break command. All I needed was already said. Thank you. --Tomas_Tintera ps. I want it because it seems to be practical to write the whole program in a one expression (usually composed of "AND" and "OR" operators). And it's nice. When reading such a code, you can feel as when reading poetry ;).

« previous php.general (#204637) next »