master101 Posted March 25, 2013 Share Posted March 25, 2013 Im trying to make a list of resources where it shows you how to make variable set like this: $user->option Link to comment https://forums.phpfreaks.com/topic/276147-who-know-how/ Share on other sites More sharing options...
akphidelt2007 Posted March 25, 2013 Share Posted March 25, 2013 That's a property in a class. To create something like that you can do it like... //say you have a user class class user { public $username = ''; function user($username) { $this->username = $username; } } $user = new user('YourName'); echo $user->username; Link to comment https://forums.phpfreaks.com/topic/276147-who-know-how/#findComment-1421014 Share on other sites More sharing options...
haku Posted March 26, 2013 Share Posted March 26, 2013 You can also just do: $user->option = 'something'; This gives you a generic object named $user, with a single property of 'option', that has a value of 'something'. Link to comment https://forums.phpfreaks.com/topic/276147-who-know-how/#findComment-1421063 Share on other sites More sharing options...
Yohanne Posted March 26, 2013 Share Posted March 26, 2013 doing good practice to declare variable" class myclass { private $val; function set_val($val) { $this->val = $val; } function get_val() { return $this->$val; } } $newval = new myclass(); $newval->set_val("my name is jayson"); echo $newval->get_val(); Link to comment https://forums.phpfreaks.com/topic/276147-who-know-how/#findComment-1421082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.