Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:52:28+00:00 2026-05-23T15:52:28+00:00

I am including one PHP script into another using PHP’s require_once() method. This script

  • 0

I am including one PHP script into another using PHP’s require_once() method. This script contains a class, TemplateAdmin, which instantiates itself right after the script, like this:

class TemplateAdmin {
// Class body...
}

$templateAdmin = new TemplateAdmin();

This was working fine for a while. However, I have adopted a new importing technique to include classes and packages. I have tested this new technique, and it works! However, for some strange reason, none of the methods in any of the classes I import are there when I need them. However, it seems as though the instance variables are still there.

For example, when a class with this absolute path is called:

require_once("C:\wamp\www\wave_audio\system\server\templates\TemplateAdmin.php");

… I get this error in the call stack:

Fatal error: Call to undefined method stdClass::top() in C:\wamp\www\wave_audio\cms\index.php on line 189

This error is referring to my use of the top() method inside of the TemplateAdmin class.

Does any one have any idea as to why this is happening??? If this helps, I have been using require_once() all along, I am running PHP 5.3.5 on a Windows XP Media Center machine.

Thank you for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:52:28+00:00Added an answer on May 23, 2026 at 3:52 pm

    Assuming you dont want to use globals here is one way that only requires a few changes.

    TemplateAdmin.php:

    class TemplateAdmin {
    // Class body...
    }
    
    return new TemplateAdmin();
    

    Return include once in import:

    function import($classes) {
    //Convert ECMAScript style directory structures to Unix style
      $address = str_replace(".", "/", $classes);
      $address = INSTALL_ROOT . "system/server/" . $address . ".php";
    
      if (file_exists($address) && is_file($address)) {
        return require_once($address);
      } else {
        die(""" . $classes . "" does not link to an existing class");
      }
    }
    

    Assign the variable:

    $adminTemplate = import('templates.TemplateAdmin');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In one PHP file, I have this code: require_once $_SERVER['DOCUMENT_ROOT'] . '/custom/functions.php'; global $testVar;
I am working on a PHP script which involves me including several external PHP
Many websites, including this one, add what are apparently called slugs - descriptive but
I am including chapters in my latex file one by one by using the
I'm trying to extend the PHP mailer class from Worx by adding a method
I have seen a few different in-process SQL databases for .NET (including one from
We have one large xslt that renders a whole shop area including products, manifacturers
One thing I've noticed with all the XML-RPC examples out there, including the spec
How do you check if a one-character String is a letter - including any
Given two colors and n steps, how can one calculate n colors including the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.