I like to see codes inside a script & learn it. I was seeing vBulletin forum's code. wondered their php class on connecting database. its like.. $var = $vbulletin->db->query_read("SELECT * FROM ..........blah...blah OR $var = $db->query_read("SELECT * FROM ......blah..blah.. just wondering, they dont even declared $var = new className; how does tht work? & if u notice, they didnt open or close mysql connection...i think the class did tht within itself.. can someone teach me abt those. I needed such class some very easy way get data from mySQL. coz its really messy if u write connection opening & clsoe code everytime use them. PS: im really weak in php class sometimes i just wonder why do u need them, u cud just use function...
Before getting into OOP, I strongly suggest you to take a look at PHP manual. Pretty much every single question you might have has been already answered somewhere - it's either PHP manual or Google.
do u really think i opened a thread here without googling it ? & my main question was abt vBulletin class....not orginal php class which i can see from php.net
They are not assigning the returned information to a class var. It is just a plain var they are assigning it to. so don't have to do anything with the $var->new class stuff. $vbulletin->var would be the way to do it in a class and you would have to define it in the class structure itself then be able to reference it outside the class. The call is just a simple sql call that gets info from the data base.
As exodus said, $var is not being defined as an object so you would not see $var = new SomeObject();. Instead, it looks like $vbulletin is an object with it's own database object "db". This db object has a "query_read" method that appears to do all the connecting/disconnecting on its own. It will most likely get the results of the query and parse them appropriately. Of course since I can't see the whole code then it could be that the connections and parsing are done in a file that is calling this one. Also, I don't think I've ever run into a situation where an object-oriented approach is "necessary" to complete the job at hand. However, it is significantly cleaner and more reusable than functional programming as all the relevant information is contained within the class. Often times people will use outside variables or local calls in functional programming that you simply can't reuse. Trust me when I tell you it's valuable to be able to use code over and over again instead of rewriting it every time.
Yea but I personally think that VB's code structure is poorly written to allow for modding etc. Purposely??..... I wouldn't doubt it. PHPBB has a way better design if you ask me. Also the two comments above are spot on in explanation.