OK You want a more generalized everday use object class.
I have a database. I dont feel like connecting to it everytime by hacking out 10 Lines of code to connect, get to the database, query the database... etc. Also what happens if I switch from MYSQL to ORACLE or something... I have to change the code on 10s of hundreds of pages. What I need then is some global file to do this that all the other programs call from. I want a class.
So I want to make some object called Database. What does the object have or what are the elements in a database. Well all databases have a table name, so that might be an element. All databases have a username and password, so those could be elements as well...etc. Now that I know what kind of elements are in this object database, I need functions or some way to get to and edit these elements in the object database. As well as functions use the elements in the Object database to Connect to edit query... etc. the database. So I might have a function chngPassword($pass) that would change the password element in the object database so that I can change the password if I need to.. I might have a Connect() which connects to the database...etc.. All of these functions describe what the Object Database does. So the elements tell what information is stored and the functions of Object Database tell how to edit the information stored and what this Object does. All of this is encapsulated (big OO programing word), into 1 file or one Object called Database.
Now the $this element is used for something special. Ok like I said before... lets say in your object database you have a username (llike we talked about)
class Database {
var $username;
now lets say you have a funtion to change the username.
function chgUser($user) {
$username = $user;
}// end function
What is wrong with this??!!? PHP looks at this and goes... hmmm.. .well he wants to create some variable $username and make it equal to $user. But thats not what we want to do!!!! We have made a variable $username up above, but PHP when it goes through the code doesnt relize that we are trying to make the
var $username up above equal the user. Instead it thinks... hey I will just create something called $username... that will ONLY be understood by the function chgUser. So what do we do to make sure PHP knows that we want to make the element, $username, and not just some variable we coooked up for that function equal to user??? the this->
By saying $this->username = $user; you are telling PHP... hey I want the element in the class to be equal to the $user and not just some variable we cooked up.
Now that is in PHP. JAVA the other language that uses this, it does something a little bit different, (Sort of).. but since this is a PHP board I wont bore you with the details.
The reason we use silly objects like Bikes and chairs, and stuff like that is that it relates the level of abstraction that we are using in laymans terms. Just like a car has elements wheels and doors and windows, and has operations (functions) like move, stop, go... a computer class has elements and operations as well... (as in the database class) it has elements like username, password, database name.....and operations (functions) like Connect, Query, etc.... They are both similar in some respects.
Last suggestion! I would suggest takeing a class or doing some research in OO (Object Oriented) Programing. If you really want to learn it (I am going to get crucified for saying this :-D ) learn JAVA or something. Its almost totally OO. Everything is a class... even the program that calls the program is a class. 🙂
Hope this all helps and good luck!