Weird PHP error message

I am getting an error in php_error_log that says:

PHP Notice:  Undefined variable: _SESSION in C:\xampp\htdocs\newdimension\public\login.php on line 3

Open in new window


I have a login.php, and at the very top is:

<?php
$pageTitle = "Login";
$errorMessage = $_SESSION['error'];

Open in new window


PHP thinks I am spelling $_SESSION as _SESSION, what the hell??!

I've looked this over and over and can't figure out why PHP would think this. Can anyone please explain this to me??
elepilAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Loganathan NatarajanLAMP DeveloperCommented:
did you put this line session_start(); on top of the page?

<?php
session_start();
$pageTitle = "Login";
$errorMessage = $_SESSION['error'];

Open in new window

elepilAuthor Commented:
Loganathan,

Okay, I can see that error I made. But even then, shouldn't the result of my error be a null $errorMessage? Why would PHP flag it as an undefined variable?
Loganathan NatarajanLAMP DeveloperCommented:
Always check to make sure the variable is set first before using it:

if(isset($_SESSION['error'])){
    $errorMessage = $_SESSION['error'];
}

Open in new window

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

elepilAuthor Commented:
My original question was why PHP was somehow interpreting my $_SESSION as _SESSION. Your answer doesn't seem to be addressing that.
Marco GasiFreelancerCommented:
This is the internal logic of Php: who bult Php decided that the Php engine always refer to variables trimming the variable identifier, that is the $ sign: $uer_name become user_name, $password becomes password and $_SESSION becomes _SESSION. To know why it does so, we should ask to the person who has decided this, but it's just curiosity. With this kind of thing we should behave as with natural phenomena: why the rain is wetting? That doesn't matter, the important is to have an umbrella ;-)
elepilAuthor Commented:
Marco,

But what causes this to happen? I want to know so I don't repeat this. This kind of error message is really annoying.
Dave BaldwinFixer of ProblemsCommented:
$_SESSION as _SESSION because the '$' is not part of the name, it is a symbol that identifies the following name as a variable.  It's an error because there are no $_SESSION variables if they haven't been created or retrieved or identified by session_start().

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Thanks for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.