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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:22:45+00:00 2026-06-03T04:22:45+00:00

After looking at this question , I tried the chosen answer myself! So basically

  • 0

After looking at this question, I tried the chosen answer myself!
So basically what I wrote was `

abstract class person
{

  function __construct()
  {
    // some code here
  }

  function myfunc()
  {
    $this->test();
  }

  abstract function test();
}

class employee extends person
{
  function __construct()
  {
    parent::__construct();
  }

  function test()
  {
    echo "So you managed to call me !!";
  }

}


$employee = new employee();
$employee->myfunc();`

When I run this script, I got an usual error
Fatal error: Using $this when not in object context on line 7.

So, how do I call an Abstract from the Parent Class?

  • EDIT

The real thing which I am trying to do is create a DatabaseObject class which holds all the common methods of different database objects and make classes extend it.

abstract class DatabaseObject {
   abstract protected function getTableName();

   public static function find_by_id($id = 0){
        global $database;
        $class = get_called_class();

        $result_array = self::find_by_sql("SELECT * FROM ". $this->getTableName() ." WHERE _id = {$id} LIMIT 1");
        echo $result_array . "<br />";
        return !empty($result_array) ? array_shift($result_array) : false;
    }

    public static function find_by_sql($sql=""){
        global $database;
        $result_set = $database->query($sql);
        $object_array = array();
        while ($row = $database->fetch_array($result_set)){
            $object_array[] = self::instantiate($row);
        }
        return $object_array;
    }
   }
}

So this is some part of my DatabaseObject Class. My User class is as follows

class User extends DatabaseObject {
    protected static $table_name = "users";

    protected function getTableName(){
        global $table_name;
        return $table_name;
    }
}

Now, whenever I do

$user = new User();
$user->findById(1);

I get the error Fatal error: Using $this when not in object context
on the line which points to

$this->getTableName();

I hope this might help in clearing up some stuff. Is there any way I can achieve this?
Thanks!

  • 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-06-03T04:22:46+00:00Added an answer on June 3, 2026 at 4:22 am

    Your code example works just fine, I don’t understand your issue Demo.

    So the code you’ve shared is not the code you talk about with the error .

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

Sidebar

Related Questions

I have been looking all over the Internet for an answer to this question
Hey so following this Question I've gotten stuck again, and yeah I've tried looking
I ask this not to start anything negative. Rather, after looking at ASP.NET MVC
I'm new to the scope of 'this' in html, javascript. So after looking at
I'm having difficulty scanning for the special character [. After looking around, I've tried:
I'll prefix this question with: No, Setting IRONPYTHONPATH is not the answer. Anyway... I
Edit: For those of you looking for an answer to the question as stated
I realize that this question spans many technologies, but I am only looking for
I found (after another question here on StackOverflow) this interesting library written in Python
probably a newbie question, but after looking through the 'net, still cannot find an

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.