[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Fatal error: Call to a member function getName() on a non-object

Posted on 2006-04-05
6
Medium Priority
?
1,919 Views
Last Modified: 2012-05-05
I tell you something chaps this is killin me!

Fatal error: Call to a member function getName() on a non-object! I have posted this problem a few times but it keeps coming back to haunt me and I am losing faith in storing objects in sessions altogether!

Some of my classes have an update method that updates a Page, a Product, an Image etc via a HTML front end. Now the Product class' update function works perfectly well, however the Page and Link class both give the Fatal Error. Each class uses the same process so it's baffling, plus all of the functions work perfectly on my local machine it's just my web server that is giving me grief!

This is the update function of the Page class:

class Page{
...

         function updatePage($_POST, $uri){
      $userId=$_SESSION['user']->getUserId();
      
      $_SESSION['page'] = unserialize($_SESSION['page']);
      $pageName=$_SESSION['page']->getName();
      $windowTitle=$_SESSION['page']->getWindowTitle();
      $HTML=$_SESSION['page']->getContent();
      serialize($_SESSION['page']);

                ***update code****
...

and the product class, which works uses the same process:

class Product{
...
         function updateProduct($_POST, $uri){


      $_SESSION['product']=unserialize($_SESSION['product']);
      $description = $_SESSION['product']->getDescription();
      $shortDescription = $_SESSION['product']->getShortDescription();
      $productName = $_SESSION['product']->getName();
      $price = $_SESSION['product']->getPrice();
      $images=$_SESSION['product']->getImageNamesArray();
      $productInCats=$_SESSION['product']->getProdInCategoryAsArray();
      $_SESSION['product']=serialize($_SESSION['product']);

               ***update code****
...

now I know the object is there because doing a var_dump($_SESSION) shows me the page object and its associated attributes. I am on PHP5 and I know register_globals is switched on with my host.I have taken the advice to include an autoload function as well to try and combat the problem but it still remains!

Please restore my faith in PHP SESSION Objects.

If i have not made myself clear please feel free to ask me to post more code or more info.

Thanks a million!!

0
Comment
Question by:jonlondon12
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16452123
Hi,

Have you made sure that your class {} code is executed before you run session_start().

When you have session_start() before your class{} definition, php will convert the objects to anonymous classes with no methods and only attributes.

-r-
0
 

Author Comment

by:jonlondon12
ID: 16452217
Hey Roonaan,

Yes my class code is executed before I run session_start, however I believe that my host has auto_session_start switched on so this may get called first. How can I get around this?

Cheers
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 16452231
Ask your host to turn that off. Personally I don't see another way.
It might be that you can use .htaccess file to do this, but this is not always allowed.

-r-
0
 

Author Comment

by:jonlondon12
ID: 16452293
yeahmy host runs PHP as a cgi module which I believe stops .htaccess from functioning correctly.

I think I may need to switch hosts as they do not seem very quick to reply to my queries.

Thanks for your help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question