i have 2 .php files
1) Parent.php with Class Parent{}
2) Child.php with Class Child{}
I am trying to extend Parent in Child as below:
Class Child extends Parent{} // gives error saying Parent not found.
Please help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You do not need to include the parent definition in the file which defines child.
Indeed some coding style rules expressly prohibit this.
The only time you will see the error being reported is at run time – and to fix you only need to ensure that the parent class has been parsed and is in scope before the child class is parsed. Including the file defining parent (where permitted by your coding style rules) is one way to accomplish this, however you must use require rather than include (ir use include with a trappable error on failure) and you must use the _once variant to ensure you don’t try to load the definition multiple times.