PHP: Fatal Error Call to a member function ... on a non-object
<p>I'm having an issue with PHP as it keeps throwing the Exception mention in the title.
It fails on the following line:</p>

<pre><code>$item-&gt;getDescription();
</code></pre>

<p>I understand what the error should mean (<code>$item</code> is null). However, $item is not null.</p>

<p>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.</p>

<p>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.</p>

<p>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).</p>

<pre><code>//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-&gt;getDescription();
}
</code></pre>

<p>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.</p>

<p>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.</p>

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