Reply to Re: When "static" isn't "static"

Your name:

Reply:


Posted by comp.lang.php on 12/05/05 22:19

I'm sorry I do not understand what you are trying to say.

Phil

Oli Filth wrote:
> comp.lang.php said the following on 05/12/2005 19:38:
> > Wow, ok, that was a surprise! I didn't think isset() had the ability
> > to declare a variable on the fly like that.
>
> It doesn't.
>
> > I was under the impression
> > that it only checked for instantiation
>
> It does.
>
> > which would be implied that if
> > a variable is not yet declared, it certainly could never be
> > instantiated as you cannot instantiate a nonexistent entity.
>
> ??
>
> >
> > That solved the problem but potentially opened up a big PHP logic flaw
> > in the process.
> >
> >
> > Oli Filth wrote:
> >
> >>comp.lang.php said the following on 05/12/2005 19:02:
> >>
> >>>[PHP]
> >>>function blah($item) {
> >>> if (!isset($baseDir)) {
> >>> static $baseDir = '';
> >>> $baseDir = $item;
> >>> print_r("baseDir = $baseDir\n");
> >>> }
> >>>
> >>> $dirID = opendir($item);
> >>> while (($fyl = readdir($dirID)) !== false) {
> >>> if (is_dir("$baseDir/$fyl")) blah($item);
> >>> // DO OTHER STUFF IF IT IS A FILE
> >>> }
> >>>}
> >>>[/PHP]
> >>>
> >>>I am using PHP 4.3.2 and the following occurs within blah() :
> >>>
> >>>[Quote]
> >>>baseDir = /home/me/stuff
> >>>baseDir = /home/me/stuff/.
> >>>baseDir = /home/me/stuff/./..
> >>>[/Quote]
> >>>
> >>>I was under the impression that a static variable retains its value
> >>>throughout a function (or method) recursive memory stack. However, it
> >>>changes everytime because it apparently loses its set value.
> >>
> >>You are using $baseDir before you have declared it static, so PHP treats
> >>it as non-static.
> >>
> >>
> >>--
> >>Oli
> >
> >
>
>
> --
> Oli

[Back to original 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

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