Unsupported operand types

Asked

Viewed 543 times

-1

foreach ( $this->_defaultModel->getFields() as $field )
    $this->data['rowNew'][$field] = null;

    /*echo("defaultModel");
    debug($this->_defaultModel);
    */

    $this->data+= $this->_defaultModel->findAllByFields($search, $page, $limitPerPage, $orderBy, $order);

I’m making a codeigniter migration Unsupported operand types

Changed the default of the operators?

  • The return of $this->_defaultModel->findAllByFields is a array?

  • No, it’s an object!

  • 1

    And what would be the expected result for an operation "array + object"?

  • I changed it to array and it’s still the same problem. Thanks for the help friend!

  • And how you turned?

1 answer

1

The variable $this->data is a array and the operator += will only work when the second operand is also a array.

$data = [0];
$data += [1, 2, 3];

print_r($data);  // [0, 1, 2, 3]

Or array associative:

$data = [0 => 'a'];
$data += [1 => 'b'];

print_r($data);  // [0 => 'a', 1 => 'b']

If the second operand is not a array, PHP will not know what to do and will trigger the error PHP Fatal error: Uncaught Error: Unsupported operand types. Therefore, we conclude that the return of $this->_defaultModel->findAllByFields is not a array. It’s up to you to see whether it should be.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.