OOP class member issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
james_k
Forum Newbie
Posts: 7
Joined: Wed May 18, 2005 9:27 am
Location: Toronto

OOP class member issue

Post by james_k »

Please consider:

Code: Select all

require(&quote;common_inc.php&quote;);

// List all projects if the user is an admin or accountant
 if ($tmsh->user_level==&quote;Admin&quote; || $tmsh->user_level==&quote;Acctg&quote;) {
 	$project=$tmsh->getProjects($order,$desc); //note that added user level is &quote;Accountant&quote; I believe, not &quote;Acctg&quote; -- for future reference when upgrading the permission tables -- james@jenxnetwork.com
 }
 // or else list only the projects the user is supposed to see.
 else {
 	$a_user=$tmsh->user_id;
 	$project=$tmsh->getProjects($order,$desc,$a_user); // this line is causing the error when adding a new project.
 }
and

Code: Select all

require ($lib_dir . &quote;timesheet.class.php&quote;);
 
 if (!isset($login_page_flag))
 { 
  session_start();
  if (!isset($session_login))   header(&quote;Location: message.php&quote;);
  else $tmsh = new TimeSheet($session_login,0);
 }
What I'm having trouble with is I'm getting an error--

Call to a member function on a non-object

The line that is causing this has been narrowed down to the one indicated in foo.php with the obvious comment. The other calls to the class function run fine, but my debugging is saying that this line is causing it.

Thoughts?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

getProjects sounds like it does not exist in that class...did you spell everything correctly (capitalization counts)
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

looks to me that $tmsh never got instantiated correctly, try var_dumping $tmsh and see if it represents the correct object
james_k
Forum Newbie
Posts: 7
Joined: Wed May 18, 2005 9:27 am
Location: Toronto

Post by james_k »

andre_c wrote:looks to me that $tmsh never got instantiated correctly, try var_dumping $tmsh and see if it represents the correct object
I think you might be right then.

var_dump($tmsh) outputs an array
shiznatix wrote:getProjects sounds like it does not exist in that class...did you spell everything correctly (capitalization counts)
getProjects() does exist in the Timesheet class, so I think andre_c is on the money here.

Does anyone have an idea about the proper way to instantiate $tmsh->getProjects() correctly in the context of foo.php? I've tried calling it from $_GLOBALS but I don't think that worked out.

Thanks for taking a moment on this thread. It's greatly appreciated. :)
james_k
Forum Newbie
Posts: 7
Joined: Wed May 18, 2005 9:27 am
Location: Toronto

Post by james_k »

Okay, well perhaps I wasn't quite clear.

A second look at the var_dump($tmsh) does indeed show that it contains the timesheet object and an array of variables.

I've been digging through the online php docs over the weekend, etc -- but I still look at that one line in foo.php and can't quite figure out why that line is throwing the error.

I mean, should the if condition return true, it assigns the return values from the function getProjects() in the timesheet class to $project, or else it should throw getProjects some different values and assign the return values to $project --

It has been mentioned that perhaps $tmsh isn't being properly instantiated -- and so I'm wondering what would be the correct way. It looks like it should be fine to me; but my tires are just spinning on this one... and I'm finding more of these little errors! (Thankfully this isn't my software, and I'm just debugging someone else's mods to this code ;) )

Edited to add:

Okay, so to further clarify things, $tmsh is instantited in the following code:

Code: Select all

<?
 
 $inc_dir  = &quote;include/&quote;;
 $disp_dir = &quote;disp/&quote;;
 $lib_dir  = &quote;lib/&quote;;
 $css_dir  = &quote;css/&quote;;
 $img_dir  = &quote;images/&quote;;
 $scripts_dir  = &quote;scripts/&quote;;
 
 require ($lib_dir . &quote;timesheet.class.php&quote;);
 
 if (!isset($login_page_flag))
 { 
  session_start();
  if (!isset($session_login))   header(&quote;Location: message.php&quote;);
  else $tmsh = new TimeSheet($session_login,0);
 }

?>
and this file "common_inc" is called in every script (including foo.php) with:

Code: Select all

require (&quote;common_inc.php&quote;);
Could it be a session issue?

Ideas/Suggestion?
Post Reply