MDanz Posted January 7, 2011 Share Posted January 7, 2011 is this calling a function or calling a method? what's the difference? $thedatabase->opendb(); class Database { function opendb() { $this->connect= mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$this->connect) { die (mysql_error()); } $db_select = mysql_select_db(DB_NAME, $this->connect); if(!$db_select) { die (mysql_error()); } } } Quote Link to comment https://forums.phpfreaks.com/topic/223724-whats-the-difference-between-a-method-and-function/ Share on other sites More sharing options...
Zurev Posted January 7, 2011 Share Posted January 7, 2011 A method, a function is a function. If it's inside of a class it's a method. The same goes for, a variable is a variable, inside of a class it's a property. On a side note, if that is your database class, have you considered making that opendb function part of your __construct method? Or at least the connection part, the select db part could be it's own function I suppose, if working with multiple databases. Either way is fine Quote Link to comment https://forums.phpfreaks.com/topic/223724-whats-the-difference-between-a-method-and-function/#findComment-1156399 Share on other sites More sharing options...
trq Posted January 8, 2011 Share Posted January 8, 2011 The only differences between functions and methods are that methods reside within a class and have automatic access to variables (properties) defined within that class. Quote Link to comment https://forums.phpfreaks.com/topic/223724-whats-the-difference-between-a-method-and-function/#findComment-1156527 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.