Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Fatal error: Call to a member function ... on a non-object</h3> <p>Happens with code similar to <code>xyz-&gt;method()</code> where <code>xyz</code> is not an object and therefore that <code>method</code> can not be called.</p> <p>This is a fatal error which will stop the script (forward compatibility notice: It will become a catchable error starting with PHP 7).</p> <p>Most often this is a sign that the code has missing checks for error conditions. Validate that an object is actually an object before calling its methods.</p> <p>A <a href="https://stackoverflow.com/search?q=%5Bphp%5D+%5Bpdo%5D+Fatal+error%3A+Call+to+a+member+function+on+a+non-object">typical</a> example would be</p> <pre><code>// ... some code using PDO $statement = $pdo-&gt;prepare('invalid query', ...); $statement-&gt;execute(...); </code></pre> <p>In the example above, the query cannot be prepared and <code>prepare()</code> will assign <code>false</code> to <code>$statement</code>. Trying to call the <code>execute()</code> method will then result in the Fatal Error because <code>false</code> is a "non-object" because the value is a boolean.</p> <p>Figure out <em>why</em> your function returned a boolean instead of an object. For example, check the <code>$pdo</code> object for the last error that occurred. Details on how to debug this will depend on how errors are handled for the particular function/object/class in question.</p> <p>If even the <code>-&gt;prepare</code> is failing then your <code>$pdo</code> database handle object <a href="https://stackoverflow.com/questions/4910796/scope-error-call-to-a-member-function-prepare-on-a-non-object">didn't get passed into the current scope</a>. Find where it got defined. Then pass it as a parameter, store it as property, or share it via the global scope.</p> <p>Another problem may be conditionally creating an object and then trying to call a method outside that conditional block. For example</p> <pre><code>if ($someCondition) { $myObj = new MyObj(); } // ... $myObj-&gt;someMethod(); </code></pre> <p>By attempting to execute the method outside the conditional block, your object may not be defined.</p> <p>Related Questions:</p> <ul> <li><a href="https://stackoverflow.com/q/54566/727208">Call to a member function on a non-object</a></li> <li><a href="https://stackoverflow.com/search?q=%5Bphp%5D+Fatal+error%3A+Call+to+a+member+function+on+a+non-object">List all PHP "Fatal error: Call to a member function ... on a non-object" Questions on Stackoverflow</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload