Re: Class Function Issue

From: Date: Sun, 17 Mar 2002 19:53:58 +0000
Subject: Re: Class Function Issue
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-88841@lists.php.net to get a copy of this message
At 17.03.2002 10:49, you wrote:
Thanks for the tip. I tried that... I passed $HTTP_SESSION_VARS as a parameter, and it didn't work. :/ I also built another function inside the class to set session variables:
        function SetSVAR($var,$value) {
                global $HTTP_SESSION_VARS;
                $HTTP_SESSION_VARS[$var] = $value;
        }
If I call $MyClass->SetSVAR($var,$Value); it works.... but if I put $this->SetSVAR($var,$Value); inside a class function it doesn't work.... I meant :
Main code ------------------------------------------ $FOO = new Yourclass $sesvar = $HTTP_SESSION_VARS; $FOO -> SetSVars($sesvar); ---------------------------------------------- CLASS yourlass var insidesesvars; { function SetSVAR($sesvar) {
        $this -> insidesesvars = $sesvars;
} } // end Yourclass There are often problems with so called globalvars like $HTTP_REFERER, $HTTP_SESSION_VARS ... using inside Objects, don´t ask me why. HTH Oliver
At 16.03.2002 22:24, you wrote:
Hi! I'm building a class, and am trying to include an authorization function.... the code works when used outside of the class, but when I
put
it inside the class, for some reason my session variables won't get set. Am I attempting the impossible, or am I missing something that I need to make this work? Below is the code for the Auth function. function Auth($username,$password) {
                $query = "SELECT id,username,sl FROM KAOPA_users where
username='$username' AND password=PASSWORD('$password')";
                $Auth = $this->Query($query);
                if ($this->number_returned($Auth) == '1') {
                        $id = mysql_result($Auth,0,"id");
                        $uname = mysql_result($Auth,0,"username");
                        $sl = mysql_result($Auth,0,"sl");
                        global $HTTP_SESSION_VARS;
                        $HTTP_SESSION_VARS["id"] = $id;
                        $HTTP_SESSION_VARS["user"] = $uname;
                        $HTTP_SESSION_VARS["sl"] = $sl;
                }
        }
some vars make trouble, using inside a class or function inside a class. Even making them global doesn´t work. Try to set the vars via an explicit function, so that they´re available inside your class, or just make them parameters so your authorisation could look like $MyClass -> Auth($username,$password,$session_vars); HTH Oliver -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#88841) next »