Reputation: 2768
I get the next notice when firing a specific function:
Trying to get property of non-object in...
My function:
private function rate($form)
{
$score = 0;
$count = $form->find('input')->length;
$score += ($count >= 2 && $count <= 5) ? INPUT_COUNT_RATE : 0;
$count = $form->find('textarea')->length;
$score += $count == 1 ? TEXTAREA_COUNT_RATE : 0;
return $score;
}
The problematic lines are the lines with the find
function.
A var_dump
of $form
returns:
object(simple_html_dom_node)[1062]...
What could be the problem?
Upvotes: 0
Views: 2624
Reputation: 360742
->find()
returns either an array of matched nodes, or null. You can't call ->length
on find results, because the results are not an object. Try
$nodes = $form->find(...);
$count = count($nodes);
Upvotes: 5