Jump to content

Little problenm


Drezard

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.