Spring Posted December 18, 2010 Share Posted December 18, 2010 I'm fairly new to OOP, could you help me fix this? Thanks! class register{ //Setting up Variables, you can add more, for example EMAIL. private $_username; private $_password; //Giving the variables values function __construct($u_name, $p_word) { $this->_username = $u_name; $this->_password = $p_word; } if(isset($_POST['submit'])) { $reg = new register($_POST['username'], $_POST['password']); echo $reg->u_name; } Notice: Undefined property: register::$u_name in C:\wamp\www\register.php on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/222075-any-idea-on-whats-going-wrong-calling-this-property/ Share on other sites More sharing options...
Mchl Posted December 18, 2010 Share Posted December 18, 2010 There is no $u_name property in this object. Maybe you want something like this: class register{ //Setting up Variables, you can add more, for example EMAIL. private $_username; private $_password; //Giving the variables values function __construct($u_name, $p_word) { $this->_username = $u_name; $this->_password = $p_word; } public function getUsername() { return $this->_username; } } //then echo $reg->getUsername(); Quote Link to comment https://forums.phpfreaks.com/topic/222075-any-idea-on-whats-going-wrong-calling-this-property/#findComment-1149025 Share on other sites More sharing options...
Spring Posted December 18, 2010 Author Share Posted December 18, 2010 How do I echo u_name that I set up from the construct? Ah, hey thanks. Quote Link to comment https://forums.phpfreaks.com/topic/222075-any-idea-on-whats-going-wrong-calling-this-property/#findComment-1149026 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.