You are here: Re: Unset won't work? « PHP Programming Language « IT news, forums, messages
Re: Unset won't work?

Posted by Marcin Dobrucki on 10/17/32 11:28

frizzle wrote:
> Hi group,
>
> Why won't $new_var be unset in the following function?
> Am i missing out something?
>
> Greetings Frizzle.
>
> *************************************
>
>
> function DoThis( $state, $fst = 1, $scnd = 2)
> {
> if( $state === 0 )
> {
> global $new_var;
> unset($new_var);

- global $new_var;
- unset($new_var);
+ unset($GLOBAL['new_var'];

See the docs for details (www.php.net/unset)

> }
> else
> {
> global $new_var;
> return $new_var = $fst + $scnd;
> };
> };
>
>
> echo DoThis( 1, 4, 8);
> echo DoThis( 0 );
> echo 'new_var= '.$new_var;

Note: you don't need ; after the curly braces. And you should
probably also initialize the $new_var before DoThis();

Anyway, IMHO, unsetting global variables within functions is a sure
way of shooting yourself in the foot. BTW, because you actually unset
the variable the last line will throw a notice about undef variable.

/m

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация