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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:47:39+00:00 2026-06-09T03:47:39+00:00

I’m having an issue with PHP as it keeps throwing the Exception mention in

  • 0

I’m having an issue with PHP as it keeps throwing the Exception mention in the title.
It fails on the following line:

$item->getDescription();

I understand what the error should mean ($item is null). However, $item is not null.

The scenario is as follows:
This is a script that syncs products from a supplier to a store. For that purpose, I have created my own class (SimpleProduct). This class has a getDescription() function.

The problem is that the data I’m receiving tend to have a lot of garbage, like items that haven’t been filled in yet. The script should skip these items and keep on iterating across the rest of the products.
This fatal error kills the entire script.

I’ve already tried implementind safeguards to prevent this from happening, but it still occurs constantly. Here’s the current code (some snippets removed as they arent pertinent to the currect case).

//This is part of a class that performs the sync

public function syncProduct($item) {

    if(empty($item)) { return "Not a product"; }
         else { var_dump($item) }

    $foo = $item->getDescription();
}

When checking the var_dump result, I get an object with some values filled in. Seeing as it is of the correct type (SimpleProduct) and it is not empty/null, I would suspect this error to stop occurring, but it still does.

Also note that several product syncs have already occurred without any errors before this one pops up, so I know the code is valid. Somehow, this specific case slips past my null-checks.

Is my null-check faulty?
How can an error for a non-object be thrown when the object in question does exist?

  • 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-06-09T03:47:42+00:00Added an answer on June 9, 2026 at 3:47 am

    Instead of checking whether if the variable is empty, why not check whether if it’s an instance of SimpleProduct?

    if ($item instanceof SimpleProduct)
    {
    
    }
    

    http://php.net/manual/en/language.operators.type.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.