![]() |
Newbi OOP Question
I am just starting to learn OOP, this very moment, and I have a question. I got a few things done (more than expected), but I am having some problems.
I am trying to just get a post from a database based on the ID. PHP Code:
PHP Code:
Thanks! ^^ |
maybe instead of echoing the $post->get_post();
You can do that within the class itself. PHP Code:
|
Wouldn't I still have to echo the get_post function in order for anything to show up? And Isn't return doing the same thing as echoing?
EDIT: Got it :) I still echoed the get_post, but in the actual function, I used echo instead of return. :) EDIT: Is there an easier way to define the stuff, instead of this? PHP Code:
|
Just for the record, when you return, you return.
The function returns the value and ends when you return, no if ands or buts! Therefor you can only return once in a function. In PHP 5, I believe "var" is being deprecated, use public and private to declare variables: PHP Code:
PHP Code:
PHP Code:
Yes, there is an easier way, use arrays: PHP Code:
|
Wow! Thanks for all that useful information!
I knew about public and private, but I get an error when I try to use them. My server says its on PHP 5, but I guess its not... I'll have to ask my host about upgrading. Thanks again. ^^ |
Your host probably runs PHP4 and PHP5 at the same time, yes it's possible, but sometimes annoying when working with PHP5, as PHP4 is dominant over the .php extension.
Try renaming your file to <name>.php5, and see if you still get the errors, if you don't, make a file over the FTP called ".htaccess", and add the following content into it: Code:
# Modify the PHP Handler |
Thanks Jay! I got some code similar to that from my host, but it didn't work. But yours fixed the problem, thanks a lot. :)
|
| All times are GMT. The time now is 05:27 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0