Solved

variable was used before it was defined

Posted on 2008-09-29
6
598 Views
Last Modified: 2012-05-05
Hi,
I always get this message from Zend Editor saying : "This variable was used before it was defined" with an orange curvy line below it. what does this exactly mean and how do I define a variable before I use it?

best regards,
0
Comment
Question by:Shopies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:Ara-
ID: 22596163
I don't know this Zend Editor, but many programming languages require / recommend that you declare a variable before using it. That means that you specify what kind of value the variable can hold (and of which size) before you assign a value to it. In PHP however the variable is declares as it first appears and is assigned a value. I guess this is a warning in Zend Editor and that it doesn't have any effect really. The script works?
0
 

Author Comment

by:Shopies
ID: 22596233
Well let me clarify something here. I'm building a login system and all the control panel files must check if the bariable $user_name is assigned or not. If yes, then the admin could use the control and if not it will prompt him back to login form or it should be. When I tried to add "index.php?act=idx&user_name=pah" in the address bar it logged me in without prompting me to the login form although I didn't login. Here is a Snippet of my .php header files which is located in the very top of my .php files
		
		if(!$user_name) {
			$log = new TemplatePower("temps/login.htm");
			$log -> prepare();
			$log -> printToScreen();
			EXIT;
		}

Open in new window

0
 

Author Comment

by:Shopies
ID: 22596240
I really don't know how to define the variable "$user_name" other than this way.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 4

Accepted Solution

by:
Ara- earned 500 total points
ID: 22596354
OK. Know I understand why you get that message. You should use the isset function:
http://no.php.net/manual/en/function.isset.php

0
 
LVL 4

Expert Comment

by:Ara-
ID: 22596393
I would also use post instead of get when dealing with a login-system. Would need some more information about how it is supposed to work etc. if I was to help you more.
0
 

Author Comment

by:Shopies
ID: 22596717
Thank you so much. exactly, the thing that I missed was the function isset and when I used it the problem has been resolved.

Many thanks buddy ;)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question