?
Solved

variable was used before it was defined

Posted on 2008-09-29
6
Medium Priority
?
600 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 4

Accepted Solution

by:
Ara- earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 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