You should declare $errors as protected instead of private. Read more about Class and Objects visibility ) Update: Ok, maybe I understand your problem now :P Try to modify your setErrors like so: public function setErrors($error) { var_dump($error);//this proves that $error is passing something... $this->errors = (array) $error;//this works (override the property) }.
You should declare $errors as protected instead of private. Read more about Class and Objects visibility ;-) Update: Ok, maybe I understand your problem now :P Try to modify your setErrors like so: public function setErrors($error) { var_dump($error);//this proves that $error is passing something... $this->errors = (array) $error;//this works (override the property) }.
Please see comment below... – Steve Took Apr 28 at 15:41 Thanks Francesco but didn't work... – Steve Took Apr 28 at 16:04 Sorry Steve, but it isn't clear what are you expecting to your code. Could you update your question with a complete example, the expected result and the actual one? – Francesco Terenzani Apr 28 at 16:18 Ok no worries, will have to get back to you, thanks.
– Steve Took Apr 28 at 16:28 1 Francesco, Ive updated the code. Basically we have a property 'errors' and set/get methods. If you ignore the constructor we are trying to add a value to the property with the set method except its not doing this.
If you set the value of the property 'error' in the constructor like in the code you get the desired results but obviously we don't want to do that, we want the setter method to do this. – Steve Took Apr 28 at 17:09.
You're declaring the errors field as private so only the class where it's declared (the abstract superclass) has access to it. You can either make it protected so subclasses can access it or implement the setErrors method in the superclass.
Beat me to it :P (the superclass part anyway) – Kevin Peno Apr 28 at 15:36 As stated below we are not trying to access the private property via inherited classes. – Steve Took Apr 28 at 15:42 @Steve "override the property with the set method and then use a public get method to return the property. " This doesn't make any sense.
What is overriding a property with a method? You cannot touch the property in the subclasses, only if the superclass exposes a method to manipulate it (or via reflection) – Artefacto Apr 28 at 16:06 The base class has the property 'errors' and a couple of methods to set and get the property however the set method is not 'setting' the data to the property. When we call the get method we get a null.
– Steve Took Apr 28 at 16:10 @Steve Then show us the implementation of that get method that's not working. – Artefacto Apr 28 at 16:33.
Private members are not visible in inherited classes. To do this you must change the visibility to protected.
We are not trying to access any members of the base class via inherited classes. We are calling a base class method from a subclass and passing a parameter. We then set the property with the passed parameter and call a get method to return the value of the property but as the question goes...the property is not being overridden.
– Steve Took Apr 28 at 15:40 Please add some example code and the actual as well as the expected results. This doesn't make sense to me - but perhaps I'm just not understanding the problem correctly. – Stefan Gehrig Apr 28 at 15:49 The property should get set via the 'setErrors()' method in the same class but its not, all the code is there.
We would then use a public get method to return the property that can be called from a subclass. – Steve Took Apr 28 at 15:55 Sorry, this doesn't make sense. $this->errors = $error even does not override the property, it rather adds $error to the $this->errors array.
– Stefan Gehrig Apr 28 at 16:02 Thanks Stefan, would you know the right way of doing this then because basically we want the value passed in $error to be stored in the base class property 'error'? – Steve Took Apr 28 at 16:13.
I find something that may help you. Am not claiming as answer :-( triconsole.com/php/oop.php killerphp.com/tutorials/object-oriented-....
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.