Page 1 of 1

Help with session and object Plz

Posted: Fri Oct 10, 2003 12:53 pm
by MillionBacteria
Okay i know this question has been asked numerous times but i haven't been able to find a solution for my problem. I can store objects in session and am able to access its methods just fine but problem arises when that object has other objects of it's own.

Code: Select all

//file: start.php
<?php

//Header
    include("JobInterface.inc");
    session_start();
    
    if(!is_object($jobInterface))
    {   echo "creating object";
        session_register('jobInterface');
        $jobInterface = new JobInterface();
     }
    
        if(session_is_registered('jobInterface');
                     $jobInterface->test(); 
?>

//file: jobInterface.inc
<?
include("Database.inc");
class JobInterface {
    var $db;
    
    function JobInterface()
     {    $this->db = new Database("");
        
     }

          function test()
          {   $this->db->connect();
          }
}
?>
Well that gives an error when it tries to access db->connect()...
Help me!!! 8O

Posted: Fri Oct 10, 2003 1:41 pm
by murph
your first error that i can see is,

Code: Select all

if(session_is_registered('jobInterface'); 
                     $jobInterface->test();
it should be

Code: Select all

if(session_is_registered('jobInterface') )
{ 
                     $jobInterface->test(); 
}
i cant debug it anymore because i dont have the file database.inc.

Posted: Fri Oct 10, 2003 1:54 pm
by MillionBacteria
Oh hehe i just wrote that part of the code on the fly..my real code is way too long to be posted here so i just made up some new functions to just clear my point. As for the database.inc, and it's connect function just connects to mysql database and i don't think it has any problems. The problem i am getting is that $this->db is not found when $jobInterface is derived from the session. If i were to just create it and call test() then it has no problem (it should anyways....hmm should check that out). But after i reload the page, $jobInterface is not instantiated but taken from the session and this is when $db object seems to just dissapear.....i hope i am being clear here.... -_-;

Error: "Call to a member function on a non-object "

Posted: Fri Oct 10, 2003 2:31 pm
by murph
Hmm, well i dont have enough experience with objects calling objects. So i cant help, why dont you just combine the two classes and just have it call a function instead of another object. That should work...

Posted: Fri Oct 10, 2003 2:54 pm
by MillionBacteria
yeah well it's just that in my class i have more than just database object.....but for now i guess i can just merge them all into a jobInterface class. It will be huge but as of right now i have no clue how to fix it... but thnx :wink:

If anyone knows what i am doing wrong plz help.