![]() |
Variable overloading issue in PHP Hi friends Thanks for visiting my post. I have a issue in object inheritance in php. I have two classes which extends other. There is one common variable name used in both the class. So it's creating a conflict while accessing the parent class variable. Let me explain this by example PHP Code: |
Re: Variable overloading issue in PHP Quote:
If you really need to declare the email variable in the subclass, then you could set the email variable in the main class to private and have a function to return the email value from the main class: PHP Code: What I would do is to not declare the $email variable in the subclass as it's already declared in the parent class. Class b could use a constructor where you can optionally pass an $email value - if you pass the email value you set the $email variable. An alternative is to use a setter function for the email in the subclass without using a constructor - example: PHP Code: |
Re: Variable overloading issue in PHP thanks CMartin your tips seems perfect. i was wrong. hi titleless, parent keyword will not work here. its only used for function not for variable. |
| All times are GMT -6. The time now is 08:31 PM. |