| 
	
 | 
 Posted by nephish on 06/18/49 11:57 
Slant wrote: 
> Fair enough.  I did not mean to be unclear.  I actually did not use the 
> $this-> specifier BECAUSE I did not want to be able to access this 
> array anywhere but within the construct.  Not defining a variable with 
> $this-> attached disallows other methods within the class from 
> accessing it, does it not?  It certainly does not work anyway.  Maybe 
> I'm missing something. 
> 
> To your question though, nephish.  I don't see a problem with what you 
> are doing.  the Session variable, after all, is just another variable. 
> You can store many things in variables, as you obviously know.  What 
> you're suggesting would work most efficiently if a single value was 
> returned from the object that the session variable is being assigned 
> to.  For example: 
> 
> 
> $frank = new Person; 
> $_SESSION['auth'] = $frank->validate('frank'); 
> 
> class frank { 
>   function validate($name) { 
>     if ($name == auth (whatever method you choose to use for 
> authorization)) { 
>       return true; 
>     } else { 
>       return false; 
>     } 
>   } 
> } 
> 
> if ($_SESSION['auth'] == true) { 
>   echo "Yea!  Fun to ensue!"; 
> } 
> 
> 
> I'd probably not place the contents of the class directly into the 
> Session variable, but instead call the object to do whatever you want, 
> then return the data in an instance variable and assign THAT to the 
> Session variable.  How does that sound? 
> 
> 
> $frank = new Person; 
> $frank->validate('frank'); 
> $_SESSION['auth'] = $frank->authorized; 
> 
> class frank { 
>   function validate($name) { 
>     if ($name == authorized (whatever method you choose to use for 
> authorization)) { 
>       $this->authorized = true; 
>     } else { 
>       $this->authorized = false; 
>     } 
>   } 
> } 
> 
> if ($_SESSION['auth'] == true) { 
>   echo "Yea!  Fun to ensue!"; 
> } 
> 
> 
> Kimmo Laine wrote: 
> > "Slant" <rcross@gmail.com> wrote in message 
> > news:1157476551.134715.190600@d34g2000cwd.googlegroups.com... 
> > > I see no reason why this should not work.  In a recent post here in 
> > > this same group, I posted a very similar example for a Database 
> > > instantiation class: 
> > > 
> > >   function __construct() { 
> > > 
> > >      $db['host'] = "localhost"; 
> > >      $db['user'] = "root"; 
> > >      $db['pass'] = ""; 
> > >      $db['name'] = "pbtportal"; 
> > > 
> > >      $link = mysql_connect($db['host'],$db['user'],$db['pass']); 
> > >      mysql_select_db($db['name'],$link); 
> > > 
> > >    } 
> > > 
> > > Works like a charm!  In this case, I did not declair the variable "$db" 
> > > but probably should have. 
> > 
> > IMHO, those aren't class members, the $db elements. You should be using the 
> > $this pointer: $this->db[...]. Now they're only visible inside the scope of 
> > the __construct method. This is't exactly the same thing that nephish was 
> > asking... 
> > 
> > Still, the way nephish was doing it works fine, your example just doesn't 
> > demonstrate it very well. 
> > 
> > -- 
> > "Ohjelmoija  on  organismi  joka  muuttaa  kofeiinia  koodiksi" - lpk 
> > http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis 
> > spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg) 
 
ok, i get you, yeah, i think thats cleaner too. 
thanks for your time. 
nephish
 
  
Navigation:
[Reply to this message] 
 |