Remember that your class has properties and it has some getter methods The properties are the private variables declared at the top of the class, for example private $_username and the getters are the methods declared below, such as public function Username() The getter Username() returns the value of the property $_username Firstly this naming is pretty nonstandard. At least, the way I would name my getters is like getUsername() or getPassword() This might start to help you understand your problem, by differentiating between the getters and the properties When you use print_r() on an object, it prints the current state of the object. The current state of the object is defined by the type of the object and the values of it's properties.As you see, in your print_r() output, it says that it's a User object with 3 private properties, _username, _password and _email.
This is correct and it has the correct values associated with them print_r() is doing what it's supposed to But then the problem with the code following is how you're trying to access these properties. Let's look at the lines: $user->Username = $this->db->escape($user->Username); $user->Password = $this->db->escape($user->Password); $user->Email = $this->db->escape($user->Email) This is not right. Firstly, to get the properties from the user you would use: $user->Username() or $user->getUsername() if you changed the naming convention.
Remember, these are functions so must be called by placing parentheses after the name of the function. They are functions that return the values from inside the object And then you're trying to set the values inside object incorrectly. For this you need to create some setter methods, like setUsername() So those lines would become: $user->setUsername($this->db->escape($user->getUsername())); $user->setPassword($this->db->escape($user->getPassword())); $user->setEmail($this->db->escape($user->getEmail())) But this is probably not the approach you really want to go for.
Why don't you escape the properties when you set them in the constructor of the class? Or escape them before you pass them to the class? It doesn't really make sense to pull them out of the class, escape them, then push them back in Hope this stuff helps.
Remember that your class has properties and it has some getter methods. The properties are the private variables declared at the top of the class, for example private $_username;, and the getters are the methods declared below, such as public function Username(). The getter Username() returns the value of the property $_username.
Firstly this naming is pretty nonstandard. At least, the way I would name my getters is like getUsername() or getPassword(). This might start to help you understand your problem, by differentiating between the getters and the properties.
When you use print_r() on an object, it prints the current state of the object. The current state of the object is defined by the type of the object and the values of it's properties. As you see, in your print_r() output, it says that it's a User object with 3 private properties, _username, _password and _email.
This is correct and it has the correct values associated with them. Print_r() is doing what it's supposed to. But then the problem with the code following is how you're trying to access these properties.
Let's look at the lines: $user->Username = $this->db->escape($user->Username); $user->Password = $this->db->escape($user->Password); $user->Email = $this->db->escape($user->Email); This is not right. Firstly, to get the properties from the user you would use: $user->Username() or $user->getUsername() if you changed the naming convention. Remember, these are functions so must be called by placing parentheses after the name of the function.
They are functions that return the values from inside the object. And then you're trying to set the values inside object incorrectly. For this you need to create some setter methods, like setUsername().
So those lines would become: $user->setUsername($this->db->escape($user->getUsername())); $user->setPassword($this->db->escape($user->getPassword())); $user->setEmail($this->db->escape($user->getEmail())); But this is probably not the approach you really want to go for. Why don't you escape the properties when you set them in the constructor of the class? Or escape them before you pass them to the class?
It doesn't really make sense to pull them out of the class, escape them, then push them back in. Hope this stuff helps.
Thank you for the solution. The reason I put it into the class was to handle the database escaping/queries in another class/model but the main values being stored/kept from the other. I'm always open on better solutions into programming as I'm forever learning.
But thank you for your solution. Shaun – Shauny Aug 3 '10 at 22:47.
Remember that your class has properties and it has some getter methods. The properties are the private variables declared at the top of the class, for example private $_username;, and the getters are the methods declared below, such as public function Username(). The getter Username() returns the value of the property $_username.
Firstly this naming is pretty nonstandard.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.