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 7619985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:49:41+00:00 2026-05-31T03:49:41+00:00

I’m having a weird problem. I’m learning PHP (used to program in Java), and

  • 0

I’m having a weird problem. I’m learning PHP (used to program in Java), and I’m trying to do one simple thing. I have a DAO method that does something like this:

while (oci_fetch($parse)) {
        $stats = new Stats();
        $stats->setId($id);
        $stats->setName($name);
        $stats->setEmail($email);
        $stats->setGender($gender);
        $stats->setBirthday($birthday);
        $statslist[] = $stats;
    }

    return $statslist;

And I have another PHP file that uses this function (called getById), as a test, like this:

    $statsdao = new StatsDAO();
    $statslist[] = $statsdao->getById(1);
    foreach ($statslist as $stat) {
        echo $stat->getName();
    }

This seems simple enough: the DAO returns an array and my other file reads the returned array of Stats and prints it. But i’m getting this error message instead:

Fatal error: Call to a member function getName() on a non-object in
/var/www/socializi/interfaceusuario/index.php on line 25

The weird thing is: if I call the foreach loop inside the DAO’s getById function, it prints it alright, but when I call the function from outside and assign it to another array, it does not recognize the array’s contents as objects.

What am I doing wrong here?
Thanks!

  • 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-31T03:49:42+00:00Added an answer on May 31, 2026 at 3:49 am

    Try it like that:

      $statsdao = new StatsDAO();
        $statslist = $statsdao->getById(1);
        foreach ($statslist as $stat) {
            echo $stat->getName();
        }
    

    You add a [] that served nothing more then put the array inside another array thus giving you

     $statslist[0][0]->getName(); //would only work on php 5.4 with this syntaxe but it shoes the idea.
    

    One level too deep.

    Put another foreach inside the first one would also fix it but its ugly and serves nothing:

     $statsdao[] = new StatsDAO();
        $statslist = $statsdao->getById(1);
        foreach ($statslist as $stats) {
             foreach ($stats as $stat) {
                 echo $stat->getName();
             }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I want to count how many characters a certain string has in PHP, but

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.