opitica Posted July 15, 2006 Share Posted July 15, 2006 What is the big difference between function(){} and class, it seems like I could create a file filled with a bunch of function(){}'s and it would still serve the same purpose as a page full of classes except for the way you call them. I see lots of sample code that have a class filled with lots of function(){}'s and not the other way around. Quote Link to comment https://forums.phpfreaks.com/topic/14654-difference-between-function-and-class/ Share on other sites More sharing options...
keeB Posted July 15, 2006 Share Posted July 15, 2006 You could say that a class is just a group of functions, but really it's so much more than that.Think of a class as a group of functions that are used to manipulate the same amount of data.Say you pull a user from the database. You would have to assign many variables accross multiple pages if you had any sort of complexity to your member system.An easier way would be..[code=php:0]$user = new user(2)[/php) (assuming user is the class, and 2 is the userid it pulls from the databse, your contructor function would populate all of the users information, which is easily grouped together and used like...[code=php:0]print "Hello ". $user->firstName . " welcome to thiswebsite. Your last login was " . $user->lastLogin[/code]It's really a small and silly example, but if you let yourself think a little at the possibilities (and this isnt the only one, polymorphism is another GREAT feature of classes)I hope this helped shed some light.. Quote Link to comment https://forums.phpfreaks.com/topic/14654-difference-between-function-and-class/#findComment-58410 Share on other sites More sharing options...
trq Posted July 15, 2006 Share Posted July 15, 2006 Really... this is like comparing apples to oranges. They are two completely different beasts. Quote Link to comment https://forums.phpfreaks.com/topic/14654-difference-between-function-and-class/#findComment-58415 Share on other sites More sharing options...
bilis_money Posted July 15, 2006 Share Posted July 15, 2006 If you are a beginner you use function. //structued programmingAn advance programmer use CLASS. //Object Oriented programmingA class may compose of variables, functions and etc.Class make you programming logic very organize.If you want full bloom OOP languages you use C++ or Java.Please take note OOP in PHP is not full bloom yet.But don't worry they are ways to make it full bloom,just go ahead and study CLASS and OOP topics.I'm sure you will find the hiden treasure. :)enjoy the info! Quote Link to comment https://forums.phpfreaks.com/topic/14654-difference-between-function-and-class/#findComment-58434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.