Hello all,
I am kind of new to PHP, but I have a heavy background in programming. Most of my development has been in C/C++, with a little bit of Perl. From an OOP point of view, I am very used to the rule that all created objects must be destroyed. What I am trying to understand in PHP is how this works? Please tell me if I am far off with the following example:
Ok so lets say I have a blog website where people can post a blog, then people can post comments to the blog. So I have a file Blog.php, which describes a Blog class. When someone goes to post a new blog, I would do something like first set up the variables, such as $body, $title, $etc, $etc... then when they hit submit, do:
$myBlog = new Blog( pass all those variables);
$myBlog->store(); // store new blog to DB
At this point I would move on to some other page, like displaying of the blog or whatever...the user may return to the home page...or if later down the road someone wants to view a blog I could do something like:
$viewBlog = new Blog( ID of the blog to get);
$viewBlog->get(); // sets all the variables of the blog from the DB
$viewBlog->display() // echo all the information to the page in some formatted way
Then, maybe they want to create a comment, I could create a new comment object, with the BlogID of the current blog being viewed, store the comment to the DB, etc etc. Then it would be easy to do:
$viewBlog->getAllComments(); // loop through and display all comments linked to blog
I think you get the picture. Throughout all of this, no object is ever destroyed, they just like float off into nothingness lol. Is this OK practice in PHP? Is this whole scenario even possible in PHP?
I look forward to, and appreciate your insight.
Thanks
Bryan