Jump to content

[SOLVED] "Fatal error: Call to a member function mk_content() on a non-object"


deadonarrival

Recommended Posts

Fatal error: Call to a member function mk_content() on a non-object in D:\Server\xampp\htdocs\pages\jonathanstory\mod_main.php on line 13

 

I get this error when I try to use a function in an included file

 

My file structure is as follows

 

INDEX.PHP - includes functions.php - includes "content" class (also where the object is created)

  |

includes mod_main.php

 

If I use a function "mk_content" in the "content" class, I get the above error... but if I use it in index.php I get no error.

 

As far as I can tell it works okay if I put the $content = new content(); in the mod_main.php file - but I didn't particularly want to have to do this in each page, I want the included pages not to have to have further includes in them (except for functions.php)

 

Hope that makes sense....

 

Anyway - my question is whether there's any other way to avoid this error without having to use the line $content = new content(); in the module (is this called creating an instance?), or do I have to do it in every included page?

Link to comment
Share on other sites

... denotes code I'm reasonably sure doesn't affect it.

 

index.php

<?
session_start();

// Need this, otherwise die
require_once("inc_functions.php");

...

if(!empty($err2))
    {
     $content->mk_content("An error has occured",date("H:i:s D dS M y"),"","$err2","");
    }

include($inc_pg);

 

Functions is included as the second line of code.

 

inc_functions.php

<?php

include_once("class/var.php");
include_once("class/db.php");
include_once("class/content.php");

$db = new db();
$db->connect();

...

?>

 

Again, the class is included before any output

Var just cleans input variables, DB is the DB connection

 

class/content.php

<?

class content {
      function mk_content($title,$date,$pic,$content,$page)
      {
        # Prints out a table with the above vars
        ...
      }
}

$content = new content();

 

The bit that confuses me is that the line in curly braces will make display correctly, but the included $inc_pg won't use the function unless I have $content = new content();in the included page. index.php seems okay with it being just in the class file.

Link to comment
Share on other sites

Ugh, now I have the same problem again, but the reason for it seems to be different :s

 

Index.php

<?
session_start();

require_once("inc_functions.php");

include("mod_blog.php");
?>

 

inc_functions.php

<?php

include_once("class/var.class.php"); $c_var = new clean();
include_once("class/db.class.php");  $c_db = new db();
include_once("class/content.class.php"); $c_content = new content();
include_once("class/news.class.php"); $c_news = new news();
# include_once("class/img_rotator.class.php"); $c_image = new image();

$c_db->connect($dhost,$duser,$dppass,$dbase);

?>

 

As far as I can tell the news.class.php should be able to use the $c_content class, but I get the same error

Fatal error: Call to a member function make() on a non-object in "D:\Server\xampp\htdocs\pages\jonathanstory\class\news.class.php on line 53"

 

Why will the class carry over to some pages, and not to other. I'm sure there's nothing using the $c_content variable this time - and as far as I can tell I'm using it all in the correct order.

 

Do I need to pass the $c_content variable to the function specifically?

ie instead of make($var) I need make($var,$c_content)

 

Any help appreciated

 

(N.B - I can't find a way to edit my posts - apologies for the triple-post)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.