Re: Variable definitions...

From: Date: Tue, 13 Nov 2001 17:09:14 +0000
Subject: Re: Variable definitions...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-74467@lists.php.net to get a copy of this message
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. HTH! 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? sjau@gmx.net
-- _______ ___ _ ____ _____ Chris Hobbs / ____\ \ / / | | |/ ___\| __ \ Head Geek | (___ \ \ / /| | | | (___ | | | | WebMaster \___ \ \ \/ / | | | |\___ \| | | | PostMaster ____) | \ / | |__| |____) | |__| | \____/ \/ \____/ \____/|_____/ http://www.silvervalley.k12.ca.us chobbs@silvervalley.k12.ca.us

« previous php.general (#74467) next »