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

  • Home
  • SEARCH
  • 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 5990865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:18:19+00:00 2026-05-22T23:18:19+00:00

All, I have the following code: public function addElements() { $newArray = array(); for

  • 0

All,

I have the following code:

public function addElements()
{
     $newArray = array();
     for ($index = 0 ; $index < count($this->listOfElements) ; $index++)
     {
           $temp = $this->listOfElements[$index];
           if (!is_null($temp) && !is_null($temp->getPlayerOb()))
           {
              echo "Player Name is: ".$temp->getPlayerOb()->getName();
              array_push($newArray, $temp);
           }
     }
}

The error line is if (!is_null($temp) && !is_null($temp->getPlayerOb())) and stack says:

Call to a member function getPlayerOb() on a non-object

I am not able to understand the issue here since I am trying to skip null values

  • 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-22T23:18:20+00:00Added an answer on May 22, 2026 at 11:18 pm

    $temp is clearly a non-object value that isn’t null. I don’t know what listOfElements is, but perhaps accessing a non-existing key gives false rather than null.

    You might check with is_object instead:

    if (is_object($temp) && !is_null($temp->getPlayerOb()))
    

    It would be better, however, to check positively. Check with instanceof and the class name:

    if (($temp instanceof SomeClass) && !is_null($temp->getPlayerOb()))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
What are the rules regarding function Overloading? I have the following code: public T
I have the following code: public function ajax() { // Contains results $data =
I have the following code to zip all the files and then save it
I have the following code: // Obtain the string names of all the elements
I have the following code I want to run, but the problem is $this->type
I have the following code: class Base { public: int x,y; Base() { x=10;
The rails books and web pages I've been following have all stuck to very
I have the following command which will loop over all the subdirectories in a
I have the following script. It replaces all instances of @lookFor with @replaceWith in

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.