Initiating a session variable inside a class

I have a basic class which verifies the login of a user and for most part it works.

The class I’m working on, basically cleans up the input fields and checks the user id/password against the database and so far this works.
after checking with the database I like to set the user name to a session variable. Here’s where its not working, the script itself is very basic nothing complicated either case I copy/pasted the part im having issues with it below.

if the user is confirmed the page is rerouted to another page which has a the following line of code to confirm the session variable
echo $_SESSION[‘test1’]; //testing

public function	userLogin()
	{  	try
			{ 	//database select statement which i took out for security reason but it was tested several time to make sure it works and it works.
				{	$this->errorStatus[] = 'user Not found'; // for testing
					[B]$_SESSION['test1'] = "Not found";    // for testing[/B]
				{	$this->errorStatus[] = 'found'; // for testing
				[B]	$_SESSION['test1'] = "found"; // for testing[/B]
			catch(PDOException $e) {  echo $e->getMessage();  }			

the highlighted code should set the session variable based on the resluts but its not…

Can you not set a session variable within a class-> method, is it out of scope???

Have you used session_start() before anyplace where you’re using the $_SESSION array?

Answering your question “Can you not set a session variable within a class-> method, is it out of scope???”.

You can set / get the value anywhere in your application because $_SESSION is a super global array the same as $_POST an $_GET. For more information see here.

Also what is the [B] in your code?? Is that when you copy and pasted it from your text editor??