pdo - PHP Catchable fatal error: Object of class could not be converted to string -


i lost here... after validating input create instance of message class , attempt insert data database:

// send message $message = $this->model->build('message', true); $message->insertmessage($uid, $user->user_id, $title, $message); 

the method insertion straight-forward:

// insert new message public function insertmessage($to_id, $from_id, $title, $body) {     $sql = "insert messages (to_id, from_id, title, body, create_date) values                                  (:to_id, :from_id, :title, :body, now())";     $sth = $this->db->prepare($sql);     return $sth->execute([':to_id' => $to_id, ':from_id' => $from_id, ':title' => $title, ':body' => $body]); } 

however, upon submission end blank page , apache error log says:

[tue jul 30 22:34:44 2013] [error] [client 127.0.0.1] php catchable fatal error: object of class framework\models\message not converted string in /var/www/p-lug/p-lug_lib/framework/models/message.php on line 18, referer: https://p-lug.localhost/message/compose/4

line 18 refers return statement, if remove return results in same error.

i've read countless links regarding error none of answers appear apply example. at no point trying convert object string or output result, , similar code insertions other classes works perfectly. in fact, code copy-pasted working example, thing changed table , data.

i've used var_dump() on variables being passed, on $this , $sth, checks out. on execute() fails. heck going on here?

so $message contains object.

this object gets passed function insertmessage 4th argument ($body still same object)

you store message object stored in variable $body in hash array passed argument execute.

the execute function attempts convert message object string finds there not __tostring function declared.

so either declare

public function __tostring() {     return $the_string; } 

or create public function/member can pass execute function.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -