Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:27:30+00:00 2026-05-29T13:27:30+00:00

Using PHP 5.3.8. I’m attempting to implement two functions, save($adoption) which serializes an Adoption

  • 0

Using PHP 5.3.8.

I’m attempting to implement two functions, save($adoption) which serializes an Adoption instance, appends a delimiter, then appends it to the end of a text file, and loadAdoptions(), which opens the text file, explode()s the contents on the delimiter, and unserialize()s each object in a for loop through the contents of the array explode() returned then calls Display() on them.

Here’s the shortest form reproducing my problem:

<html><head><title>Request Processed</title></head><body>
<?php
class Dog {
    var $name; 
}

class Adoption
{
    var $dog;

    function Display()
    {
        echo $dog->name;
    }
}

function save($adoption)
{
    file_put_contents("../adoptions/adoptions.txt", (serialize($adoption)."<!-- E -->"));
 }

function loadAdoptions()
{
    $filename = '../adoptions/adoptions.txt';
    if (file_exists($filename)) 
    {
        $datain = file_get_contents($filename);
        $out = explode("<!-- E -->", $datain);

        echo "<br /><u>Retrieved Data</u><br />";
        $count = count($out);
        echo 'Count: '.$count;

        for ($i = 0; i < $count; $i++)
        {
            $curAdoption = unserialize($out[i]);
           if (curAdoption)
                echo $curAdoption->Display();
            else
                echo 'Error Reading Record.';
            echo '<br />';
        }

    }
}

$newDog = new Dog();
$newDog->name = "Scruffles";
$newAdoption = new Adoption();
$newAdoption->dog = newDog;
save(newAdoption);
loadAdoptions();
?>
</body></html>

On line 38, where Display() is called, Fatal error: Call to a member function Display() on a non-object

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:27:31+00:00Added an answer on May 29, 2026 at 1:27 pm

    Quite a few times, you’ve missed the $ off the front of a variable. Also to access a class’s member variable from a method (getting dog’s name in Display() you need to use $this->dog.

    Working source:

    <html><head><title>Request Processed</title></head><body>
    <?php
    class Dog {
        var $name; 
    }
    
    class Adoption
    {
        var $dog;
    
        function Display()
        {
            echo $this->dog->name;
        }
    }
    
    function save($adoption)
    {
        file_put_contents("../adoptions/adoptions.txt", (serialize($adoption)."<!-- E -->"));
     }
    
    function loadAdoptions()
    {
        $filename = '../adoptions/adoptions.txt';
        if (file_exists($filename)) 
        {
            $datain = file_get_contents($filename);
            $out = explode("<!-- E -->", $datain);
    
            echo "<br /><u>Retrieved Data</u><br />";
            $count = count($out);
            echo 'Count: '.$count;
    
            for ($i = 0; $i < $count; $i++)
            {
                $curAdoption = unserialize($out[$i]);
               if ($curAdoption)
                    echo $curAdoption->Display();
                else
                    echo 'Error Reading Record.';
                echo '<br />';
            }
    
        }
    }
    
    $newDog = new Dog();
    $newDog->name = "Scruffles";
    $newAdoption = new Adoption();
    $newAdoption->dog = $newDog;
    save($newAdoption);
    loadAdoptions();
    ?>
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php and mysql I have two tables, a users table and a profiles
Using PHP's Image and GD functions you can use the following method to finally
Using php-sdk I obtain pages in this way: $array = $this->instance->api( '/' . $fb_user
Using php I authenticate a user, then behind the scenes,they are then again authenticated
Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
Using PHP's DOM functions, how do you convert a DOM Node's contents into a
Using PHP, I'm trying to populate an HTML list with data from two different
Using PHP to extract data from SQL and then creating a .csv file on
Using PHP I'm attempting to take an HTML string passed from a WYSIWYG editor
Using php, I'm trying to create a script which will search within a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.