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

Posted on 2006-04-05
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){
      $_SESSION['page'] = unserialize($_SESSION['page']);

                ***update code****

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

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

      $description = $_SESSION['product']->getDescription();
      $shortDescription = $_SESSION['product']->getShortDescription();
      $productName = $_SESSION['product']->getName();
      $price = $_SESSION['product']->getPrice();

               ***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!!

Question by:jonlondon12
    LVL 49

    Expert Comment


    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.


    Author Comment

    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?

    LVL 49

    Accepted Solution

    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.


    Author Comment

    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

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now