Object could not be converted to string?
Why am I getting this error:
Catchable fatal error: Object of class Card could not be converted to
string in /f5/debate/public/Card.php on line 79
Here is the code:
public function insert()
{
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards
VALUES('$this->$type','$this->$tag','$this->$author->$last','$this->$author->$first',
'$this->$author->$qualifications','$this->$date->$year','$this->$date->$month',
'$this->$date->$day','$this->$title', '$this->$source', '$this->$text')";
$mysql->execute($query);
}
(Line 79 is the $query
and the function is part of class Card
)
All the declarations of Card
:
public $type;
public $tag;
public $title;
public $source;
public $text;
public function __construct() {
$this->date = new Date;
$this->author = new Author;
}
After changing line 79 to this:
$query = "INSERT INTO cards
VALUES('$this->type','$this->tag','$this->author->last','$this->author->first',
'$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day',
'$this->title', '$this->source', '$this->text')";
I now get this error:
Catchable fatal error: Object of class Author could not be converted
to string in /f5/debate/public/Card.php on line 79
php
add a comment |
Why am I getting this error:
Catchable fatal error: Object of class Card could not be converted to
string in /f5/debate/public/Card.php on line 79
Here is the code:
public function insert()
{
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards
VALUES('$this->$type','$this->$tag','$this->$author->$last','$this->$author->$first',
'$this->$author->$qualifications','$this->$date->$year','$this->$date->$month',
'$this->$date->$day','$this->$title', '$this->$source', '$this->$text')";
$mysql->execute($query);
}
(Line 79 is the $query
and the function is part of class Card
)
All the declarations of Card
:
public $type;
public $tag;
public $title;
public $source;
public $text;
public function __construct() {
$this->date = new Date;
$this->author = new Author;
}
After changing line 79 to this:
$query = "INSERT INTO cards
VALUES('$this->type','$this->tag','$this->author->last','$this->author->first',
'$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day',
'$this->title', '$this->source', '$this->text')";
I now get this error:
Catchable fatal error: Object of class Author could not be converted
to string in /f5/debate/public/Card.php on line 79
php
That's because of$this-$author->qualifications
– quantumSoup
Jul 8 '10 at 5:51
add a comment |
Why am I getting this error:
Catchable fatal error: Object of class Card could not be converted to
string in /f5/debate/public/Card.php on line 79
Here is the code:
public function insert()
{
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards
VALUES('$this->$type','$this->$tag','$this->$author->$last','$this->$author->$first',
'$this->$author->$qualifications','$this->$date->$year','$this->$date->$month',
'$this->$date->$day','$this->$title', '$this->$source', '$this->$text')";
$mysql->execute($query);
}
(Line 79 is the $query
and the function is part of class Card
)
All the declarations of Card
:
public $type;
public $tag;
public $title;
public $source;
public $text;
public function __construct() {
$this->date = new Date;
$this->author = new Author;
}
After changing line 79 to this:
$query = "INSERT INTO cards
VALUES('$this->type','$this->tag','$this->author->last','$this->author->first',
'$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day',
'$this->title', '$this->source', '$this->text')";
I now get this error:
Catchable fatal error: Object of class Author could not be converted
to string in /f5/debate/public/Card.php on line 79
php
Why am I getting this error:
Catchable fatal error: Object of class Card could not be converted to
string in /f5/debate/public/Card.php on line 79
Here is the code:
public function insert()
{
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards
VALUES('$this->$type','$this->$tag','$this->$author->$last','$this->$author->$first',
'$this->$author->$qualifications','$this->$date->$year','$this->$date->$month',
'$this->$date->$day','$this->$title', '$this->$source', '$this->$text')";
$mysql->execute($query);
}
(Line 79 is the $query
and the function is part of class Card
)
All the declarations of Card
:
public $type;
public $tag;
public $title;
public $source;
public $text;
public function __construct() {
$this->date = new Date;
$this->author = new Author;
}
After changing line 79 to this:
$query = "INSERT INTO cards
VALUES('$this->type','$this->tag','$this->author->last','$this->author->first',
'$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day',
'$this->title', '$this->source', '$this->text')";
I now get this error:
Catchable fatal error: Object of class Author could not be converted
to string in /f5/debate/public/Card.php on line 79
php
php
edited Sep 18 '15 at 9:36
hg8
7411124
7411124
asked Jul 8 '10 at 5:37
cactusbincactusbin
3711311
3711311
That's because of$this-$author->qualifications
– quantumSoup
Jul 8 '10 at 5:51
add a comment |
That's because of$this-$author->qualifications
– quantumSoup
Jul 8 '10 at 5:51
That's because of
$this-$author->qualifications
– quantumSoup
Jul 8 '10 at 5:51
That's because of
$this-$author->qualifications
– quantumSoup
Jul 8 '10 at 5:51
add a comment |
6 Answers
6
active
oldest
votes
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.
add a comment |
I don't think you need the $ sign when using arrow operator.
add a comment |
you shouldn't put $ before property names when you access them:
public function insert() {
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards VALUES('$this->type','$this->tag','$this->author->last','$this->author->first','$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day','$this->title', '$this->source', '$this->text')";
$mysql->execute($query);
}
add a comment |
You are trying to echo an object itself, not a string property of it. Check your code carefully.
add a comment |
You probably want to use:
$query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc
add a comment |
I think one of the object doesn't have toString() method defined so it cannot be represented as string.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3200899%2fobject-could-not-be-converted-to-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
edited Jul 8 '10 at 5:52
answered Jul 8 '10 at 5:46
Felix KlingFelix Kling
560k130870931
560k130870931
add a comment |
add a comment |
I don't think you need the $ sign when using arrow operator.
add a comment |
I don't think you need the $ sign when using arrow operator.
add a comment |
I don't think you need the $ sign when using arrow operator.
I don't think you need the $ sign when using arrow operator.
answered Jul 8 '10 at 5:43
uvgroovyuvgroovy
43539
43539
add a comment |
add a comment |
you shouldn't put $ before property names when you access them:
public function insert() {
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards VALUES('$this->type','$this->tag','$this->author->last','$this->author->first','$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day','$this->title', '$this->source', '$this->text')";
$mysql->execute($query);
}
add a comment |
you shouldn't put $ before property names when you access them:
public function insert() {
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards VALUES('$this->type','$this->tag','$this->author->last','$this->author->first','$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day','$this->title', '$this->source', '$this->text')";
$mysql->execute($query);
}
add a comment |
you shouldn't put $ before property names when you access them:
public function insert() {
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards VALUES('$this->type','$this->tag','$this->author->last','$this->author->first','$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day','$this->title', '$this->source', '$this->text')";
$mysql->execute($query);
}
you shouldn't put $ before property names when you access them:
public function insert() {
$mysql = new DB(debate);
$this->initializeInsert();
$query = "INSERT INTO cards VALUES('$this->type','$this->tag','$this->author->last','$this->author->first','$this-$author->qualifications','$this->date->year','$this->date->month','$this->date->day','$this->title', '$this->source', '$this->text')";
$mysql->execute($query);
}
answered Jul 8 '10 at 5:39
Sergey EreminSergey Eremin
9,15913244
9,15913244
add a comment |
add a comment |
You are trying to echo an object itself, not a string property of it. Check your code carefully.
add a comment |
You are trying to echo an object itself, not a string property of it. Check your code carefully.
add a comment |
You are trying to echo an object itself, not a string property of it. Check your code carefully.
You are trying to echo an object itself, not a string property of it. Check your code carefully.
answered Jul 8 '10 at 5:39
Jacob RelkinJacob Relkin
136k24317303
136k24317303
add a comment |
add a comment |
You probably want to use:
$query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc
add a comment |
You probably want to use:
$query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc
add a comment |
You probably want to use:
$query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc
You probably want to use:
$query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc
answered Jul 8 '10 at 5:40
quantumSoupquantumSoup
15k73453
15k73453
add a comment |
add a comment |
I think one of the object doesn't have toString() method defined so it cannot be represented as string.
add a comment |
I think one of the object doesn't have toString() method defined so it cannot be represented as string.
add a comment |
I think one of the object doesn't have toString() method defined so it cannot be represented as string.
I think one of the object doesn't have toString() method defined so it cannot be represented as string.
answered Jul 8 '10 at 6:34
Alex KleshchevnikovAlex Kleshchevnikov
121214
121214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3200899%2fobject-could-not-be-converted-to-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
That's because of
$this-$author->qualifications
– quantumSoup
Jul 8 '10 at 5:51