PHP Classes

how to use this in a custom function

Recommend this page to a friend!

      My Session  >  All threads  >  how to use this in a custom function  >  (Un) Subscribe thread alerts  
Subject:how to use this in a custom function
Summary:how to use this in a custom function
Messages:2
Author:leocrawf stewart
Date:2012-11-09 06:50:48
Update:2012-11-21 10:55:07
 

  1. how to use this in a custom function   Reply   Report abuse  
Picture of leocrawf stewart leocrawf stewart - 2012-11-09 06:50:48
I want to use this in a custom function but it does not work. here is my code:

require_once('../../includes/mySession.class.php');
require_once('../../includes/mySession.conf.php');
$session = mySession::getIstance($_MYSESSION_CONF);

function customFunction(){
//get custom db connection
$session->save("foo","bar");

}

I get a "Undefined variable: session";

  2. Re: how to use this in a custom function   Reply   Report abuse  
Picture of Jaroslav Jaroslav - 2012-11-21 10:55:07 - In reply to message 1 from leocrawf stewart
Hi,
try

function customFunction($session){
//get custom db connection
$session->save("foo","bar");
}

or

function customFunction($session){
global $session;
//get custom db connection
$session->save("foo","bar");
}

;)