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

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

 



Tomas Tintera wrote:
> 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.

Well it most certainly cannot be a local variable, and you have to use
'global' inside your function to see it if it's going to be seen at all.

If you want this to apply to variables inside the scope of another
function calling this function, you'd still want 'global', I think to have
any hope of making it work.

> 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()).

You would need to include 'global $a' in the $php code to be eval-ed.

> 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).

eval in general is usually not a good idea. :-)

> 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 ;).

It sounds to me like you would be happier programming in a language such
as Lisp, Forth, or Scheme, or maybe even Prolog.

These languages all conform (more or less) to your desired syntax goal.

PHP doesn't.

Trying to hack something in there that will do what you desire will
probably only lead to bugs and big-time maintenance problems.

Or you could write your own language, sort of like PHP, only with none of
the specialized language constructs and make everything a function (like
Lisp and all those mentioned above).

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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