We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Object of class stdClass could not be converted to string

Trying to run that code:


        $user = parent::me();

        $user->nome        = $this->request->getPost('nome');
        $user->celular     = $this->request->getPost('celular');
        $user->birthday    = \DateTime::createFromFormat('d/m/Y', $this->request->getPost('birthday'))->format('Y-m-d H:i:s');
        $user->cep         = $this->request->getPost('cep');
        $user->rua         = $this->request->getPost('rua');
        $user->numero      = $this->request->getPost('numero');
        $user->complemento = $this->request->getPost('complemento');
        $user->bairro      = $this->request->getPost('bairro');
        $user->cidade      = $this->request->getPost('cidade');
        $user->estado      = $this->request->getPost('estado');
        $user->updatedAt   = date('y-m-d H:i:s');

        if ($user->usertype == 2) {
            $user->bank      = $this->request->getPost('bank');
            $user->ag        = $this->request->getPost('ag');
            $user->cc        = $this->request->getPost('cc');
            $user->profissao = $this->request->getPost('profissao');
        }

        try {
            $user->save(); // line 301

Returning: Catchable fatal error: Object of class stdClass could not be converted to string in line 301

Someone can help me?

Ps parent::me() -> User::findFirstByUser_id($this->session->get('user')['user_id']); Ps2 $user seems to be ok, the error occurs only on save



145.0k
Accepted
answer

Some property which is column have stdclass value and it can't be converted to string.



43.9k

Hi,

following the given suggestion, comment line 301 and put a var_dump($user) on its place

Solved the issue. I was overriding one property with an object in afterFetch method, so wehn try to save some record it have the object =/ Thx for your sup

Hi,

following the given suggestion, comment line 301 and put a var_dump($user) on its place