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 3970320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:04:20+00:00 2026-05-20T04:04:20+00:00

As far as I thought you could either instantiate the class as so: $class

  • 0

As far as I thought you could either instantiate the class as so:

$class = new className();

Then to use a method in it you would just do:

$class->myMethod();

Or if you wanted to use something from within the class WITHOUT instantiating it you could do:

className::myMethod();

I’m sure I have used the latter before without any problems, but then why am I getting an error that says:

Fatal error: Using $this when not in object context

My code I am using to call it is:

// Display lists with error message
manageLists::displayLists($e->getMessage());

The class is as follows..

class manageLists {

    /* Constructor */

    function __construct() {
        $this->db_connection = connect_to_db('main');
    }

    function displayLists($etext = false, $success = false) {

        // Get list data from database
        $lists = $this->getLists();

        ......

    }

    function getLists() {

        .........

    }

}

I am getting that error from this line..

$lists = $this->getLists();
  • 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-20T04:04:21+00:00Added an answer on May 20, 2026 at 4:04 am

    When you use the format ClassName::methodName(), you are calling the method ‘statically’, which means you’re calling the method directly on the class definition and not on an instance of the class. Since you can’t call static methods from an instance, and $this represents the instance of the class, you get the fatal error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thus far used sql server stored procedures for all my web applications... Now thought
As far as I know, what I ask here isn't possible, but I thought
I haven't gotten far enough into Python to make GUIs yet, so I thought
Here's what I got so far (that doesn't work). At this point I thought
So, I thought I'd try my luck on ASP.NET. I didn't get very far
I am having trouble learning the purpose of XSD documents, and would like either
I thought a great way to test my understanding of generic functions would be
As a challenge to my beginner programming ability I thought it would be fun
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
So far I've found two different ways to access what I believe are equivalent

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.