Jump to content

[SOLVED] Using function variables outside a class?


ChadNomad

Recommended Posts

Heres the setup. Maybe this will make more sense. I'm trying to use a variable from a function inside a class and use that in a completely different page where the class file is included.

 

login.class.php

class Login()
{
   function ProcessLogin($username, $password)
   {
       $this->MyVar = "Hello";
   }
}

$login = new Login();
$login->ProcessLogin($username, $password)

 

login.php

include("login.class.php");

echo $login->MyVar; // <- This is my problem. Doesn;t work... 

 

I've tried using "global" to no avail...

Use:

class Login()
{
var MyVar;
   function ProcessLogin($username, $password)
   {
       $this->MyVar = "Hello";
   }
}

$login = new Login();
$login->ProcessLogin($username, $password)

Then try:

 

include("login.class.php");

echo $login->MyVar; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.