php - Fatal error when extending included class -
i trying simple thing here doesn't seem work. take @ code:
include 'custom/mainclass.php'; $child = new childclass(); class childclass extends mainclass { } apparently childclass() cannot found (according php).. i'm 100% sure i'm doing stupid in way of ordering code.
i searched web understand i'm doing nothing wrong..
you have declare classes in code first before using them.
include 'custom/mainclass.php'; class childclass extends mainclass { } $child = new childclass(); //create instance after class has been declared edit:
after research turned out, can use class before declaring it. but, declaration of class , parent classes must in same file.
so if declare parent class in 1 file , child class in another, won't work.
also, must declare parent classes first. after can extend them.
Comments
Post a Comment