Object could not be converted to string?












14















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











share|improve this question

























  • That's because of $this-$author->qualifications

    – quantumSoup
    Jul 8 '10 at 5:51
















14















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











share|improve this question

























  • That's because of $this-$author->qualifications

    – quantumSoup
    Jul 8 '10 at 5:51














14












14








14


2






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











share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












6 Answers
6






active

oldest

votes


















9














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.






share|improve this answer

































    6














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






    share|improve this answer































      3














      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);
      }





      share|improve this answer































        2














        You are trying to echo an object itself, not a string property of it. Check your code carefully.






        share|improve this answer































          2














          You probably want to use:



          $query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc





          share|improve this answer































            2














            I think one of the object doesn't have toString() method defined so it cannot be represented as string.






            share|improve this answer























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              9














              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.






              share|improve this answer






























                9














                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.






                share|improve this answer




























                  9












                  9








                  9







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 8 '10 at 5:52

























                  answered Jul 8 '10 at 5:46









                  Felix KlingFelix Kling

                  557k130864924




                  557k130864924

























                      6














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






                      share|improve this answer




























                        6














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






                        share|improve this answer


























                          6












                          6








                          6







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






                          share|improve this answer













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







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jul 8 '10 at 5:43









                          uvgroovyuvgroovy

                          43539




                          43539























                              3














                              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);
                              }





                              share|improve this answer




























                                3














                                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);
                                }





                                share|improve this answer


























                                  3












                                  3








                                  3







                                  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);
                                  }





                                  share|improve this answer













                                  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);
                                  }






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jul 8 '10 at 5:39









                                  Sergey EreminSergey Eremin

                                  9,13913244




                                  9,13913244























                                      2














                                      You are trying to echo an object itself, not a string property of it. Check your code carefully.






                                      share|improve this answer




























                                        2














                                        You are trying to echo an object itself, not a string property of it. Check your code carefully.






                                        share|improve this answer


























                                          2












                                          2








                                          2







                                          You are trying to echo an object itself, not a string property of it. Check your code carefully.






                                          share|improve this answer













                                          You are trying to echo an object itself, not a string property of it. Check your code carefully.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Jul 8 '10 at 5:39









                                          Jacob RelkinJacob Relkin

                                          135k24316303




                                          135k24316303























                                              2














                                              You probably want to use:



                                              $query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc





                                              share|improve this answer




























                                                2














                                                You probably want to use:



                                                $query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc





                                                share|improve this answer


























                                                  2












                                                  2








                                                  2







                                                  You probably want to use:



                                                  $query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc





                                                  share|improve this answer













                                                  You probably want to use:



                                                  $query = "INSERT INTO cards VALUES('$this->type','$this->tag' // etc






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jul 8 '10 at 5:40









                                                  quantumSoupquantumSoup

                                                  14.9k73453




                                                  14.9k73453























                                                      2














                                                      I think one of the object doesn't have toString() method defined so it cannot be represented as string.






                                                      share|improve this answer




























                                                        2














                                                        I think one of the object doesn't have toString() method defined so it cannot be represented as string.






                                                        share|improve this answer


























                                                          2












                                                          2








                                                          2







                                                          I think one of the object doesn't have toString() method defined so it cannot be represented as string.






                                                          share|improve this answer













                                                          I think one of the object doesn't have toString() method defined so it cannot be represented as string.







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Jul 8 '10 at 6:34









                                                          Alex KleshchevnikovAlex Kleshchevnikov

                                                          121214




                                                          121214






























                                                              draft saved

                                                              draft discarded




















































                                                              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.




                                                              draft saved


                                                              draft discarded














                                                              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





















































                                                              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







                                                              這個網誌中的熱門文章

                                                              Tangent Lines Diagram Along Smooth Curve

                                                              Yusuf al-Mu'taman ibn Hud

                                                              Zucchini