Drezard Posted April 6, 2007 Share Posted April 6, 2007 Okay, Little OOP Problem. I have 3 files (file1.php, file2.php, file3.php) Now heres the code for the 3 files... (I know it does nothing its an example): file1.php: <?php class file1 { function filefunction () { echo "Good morning"; } } ?> file2.php: <?php class file2 { function filefunction2 () { $file1->filefunction(); } } file3.php: <?php include('file1.php'); include('file2.php'); $file1 = new file1; $file2 = new file2; $file2->filefunction2(); ?> Now when i run this code (file3.php), it gives me this error: Fatal error: Call to a member function filefunction() on a non-object in C:\Program Files\xampp\htdocs\file2.php on line 8 what can i do to make this work and stop that error? (remember code is an example not the real thing) - cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/45866-little-problenm/ Share on other sites More sharing options...
Lumio Posted April 6, 2007 Share Posted April 6, 2007 You need to make a new instance of file1: <?php class file2 { function filefunction2 () { $file1 = new file1; $file1->filefunction(); } } Link to comment https://forums.phpfreaks.com/topic/45866-little-problenm/#findComment-222828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.