Conversion error "Array to string Conversion" in PHP 7

Asked

Viewed 1,159 times

0

I tried to revise a little, but every time I pass by it I can not see the mistake made. The error of notice is :

Notice: Array to string conversion in ../library/DAO.php on line 781

And the function he points to is:

private function setObjFromSqlWithId($result, DTO $dto) {
        $objArray = array();
        if ($result) {
            foreach ($result as $linha) {
                $dto = null;
                foreach ($linha as $key => $value) {
                    $object = $this->objectsSql[$key];
                    if ($dto == null)
                        $dto = new $object[0]();
                    $dto->$object[1]($value);
                }
                $objArray[] = clone $dto;
            }
        }
        else {
            return array();
        }
        return $objArray;
    }

It may be that because the PHP version change has changed something but I can’t find it. Please if anyone knows help me.

Error that appears a little below:

Fatal error: Uncaught Error: Function name must be a string in .../library/DAO.php:781 Stack trace: #0 .../library/DAO.php(751): DAO->setObjFromSqlWithId(Array, Object(Usuario)) #1 .../library/DAO.php(189): DAO->execSql('\tSELECT id as i...', Object(Usuario)) #2 .../persistencia/UsuarioDAO.php(15): DAO->getByPk(Object(Usuario), '8') #3 .../controle/ControlLogin.php(29): UsuarioDAO->getDTO('8') #4 .../library/Controller.php(266): ControlLogin->home() #5 .../library/Controller.php(305): Controller->listener() #6 .../index_01.php(31): Controller->loadModule() #7 {main} thrown in .../library/DAO.php on line 781
  • No problem with the version. What is the line of the error?

  • $dto->$Object1;

  • 1

    My hunches $object is a string so the [1] is hitting a character.

  • I understand, I edited with the fatal error that appears, but I’m not able to interpret the error

  • Imprisons the $dto->$object[1] or gives a var_dump(). See if it feels right $dto->$object and $dto->object are different things.

  • I had already tried to see if it was syntax the notice some but the fatal error continues in the same line

  • The error missing says an array has been passed instead of a string to call the method. You need to parse the value of $object

  • If I echo him, he prints me Usuariogetid

  • Every time?

  • Yes, I put the echo inside the for it prints the Usuariogetid

Show 5 more comments
No answers

Browser other questions tagged

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