Object could not be converted to string?

Read about string parsing, you have to enclose the variables with brackets {}:

$query = "INSERT INTO cards VALUES('$this->type','$this->tag','{$this->author->last}',"

Whenever you want to access multidimensional arrays or properties of a property in string, you have to enclose this access with {}. Otherwise PHP will only parse the variable up to the first [i] or ->property.

So with "$this->author->last" instead of "{$this->author->last}", PHP will only parse and evaluate $this->author which gives you the error as author is an object.


I don't think you need the $ sign when using arrow operator.

Tags:

Php