![]() | | ||||||||
| | #1 |
| Warrior Member Join Date: Jun 2009
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
|
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: |
| | |
| | |
| | #2 | |
| HyperActive Warrior War Room Member Join Date: Oct 2002
Posts: 360
Thanks: 112
Thanked 48 Times in 39 Posts
| 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: | |
| | |
| | #3 |
| Warrior Member Join Date: Jun 2009
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
|
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. |
| | |
| | |
![]() |
|
| Tags |
| issue, overloading, php, variable |
| Thread Tools | |
| |
![]() |