Reputation: 921
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.
Upvotes: 0
Views: 81
Reputation: 48357
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.
Upvotes: 1
Reputation: 5664
you have to include parent.php file and also change Parent class name.
Parent is a keyword so you could try by changing your class name
I hope this will help you.
Upvotes: 1