BTW, the official explanation is wrong.
"local part this variable is destroyed and declared again"
is incorrect. The global variable is not destroyed. The local namespace
pushes the variable name onto the stack and gives it a value for the
duration of the function. Every time you try and access this variable it is
taken from the stack by the parser. Once you exit the function the local
namespace is destroyed and all the local variables are popped from the
stack. If the call stack is in the Global area then all variabels are
accessed from the heap, so your original variable (and its original value)
are still accessible.
> -----Original Message-----
> From: Chris Hobbs [mailto:[EMAIL PROTECTED]]
> Sent: 13 November 2001 17:09
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [PHP] Variable definitions...
> Hi Stephan,
> IMHO, I think the answer requested is the only one that really makes
> sense - as soon as I read it, _my_ first thought went to scope.
> If a variable changes values, the other value is no longer usable, and
> thus there aren't really two variables with the same name in that case.
> When comparing global to local scope, however, you can definitely have
> the same name in use in two places.
> Of course, I wasn't a CS major, so someone else might be able to give
> you an answer that will help you justify yours - but prima facie, you
> got it wrong :(
> Now, if you're talking about the compiler level, then no two variables
> (which are actually memory registers at this point, iirc) can share the
> same memory space with different values - this is just logically
> impossible. But the question is certainly referring to source code, and
> so scope is the only reasonable answer.
> Stephan wrote:
> > Hello,
> > first of all I didn't exactely know where the right place is to ask this
> > question.
> > Well, my problem is that I just had some exams and am very unhappy on
> > how certain things were rated.
> > There's especially one question and I try to translate it as exact as
> > possible:
> > When is it possible that two variables have the same name but display
> > different variables?
> > The official solution was when in a script a global variable is declared
> > and then in a local part this variable is destroyed and declared again
> > with the same name (maybe even using different data type).
> > As for me, I'm of the opinion that this definition according to the
> > question is too narrow minded. I think that a variable is already
> > different if the the value within the variable is changed due to script
> > OR if you appoint a new value to the variable OR if the variable is an
> > array and some elements are accessed / elements are added / elements are
> > removed.
> > The reason why I think variables with different values can be considered
> > as different variable according to the question asked in the exam is
> > that when you declare a variable it also has a value even if this value
> > is NULL.
> > Now I'd like very much to hear your opinion on this issue since for me
> > very much depends on that (3 years of studying at college).
> > Stephan
> > P.S.: If you agree with me or not can you also send me an email to me?
> > [EMAIL PROTECTED]
> _______ ___ _ ____ _____
> Chris Hobbs / ____\ \ / / | | |/ ___\| __ \
> Head Geek | (___ \ \ / /| | | | (___ | | | |
> WebMaster \___ \ \ \/ / | | | |\___ \| | | |
> PostMaster ____) | \ / | |__| |____) | |__| |
> \____/ \/ \____/ \____/|_____/
> [EMAIL PROTECTED]
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]