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 Quote 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 (edited) 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; Edited March 25, 2013 by akphidelt2007 Quote 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'. Quote 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(); Quote Link to comment https://forums.phpfreaks.com/topic/276147-who-know-how/#findComment-1421082 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.