Guest 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 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(); 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...
Guest Posted December 18, 2010 Share Posted December 18, 2010 How do I echo u_name that I set up from the construct? Ah, hey thanks. 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
Archived
This topic is now archived and is closed to further replies.