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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:10:12+00:00 2026-06-04T15:10:12+00:00

I am trying to learn how to use LSB. I am trying to separate

  • 0

I am trying to learn how to use LSB. I am trying to separate my common db methods into class DatabaseObject and extend it to all classes that will be using them. Common db methods being find_by_id(), create(), delete(), etc.

$username = trim($_POST['username']);
$password = trim($_POST['password']);

$found_personnel = Personnel::authenticate($username, $password);

Classes

class DatabaseObject {


  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;
  }

  private static function instantiate($record) {
    $object = new self;

    foreach($record as $attribute=>$value){
        if ($object->has_attribute($attribute)) {
            $object->$attribute = $value;
        }
    }
    return $object;
  }

  private function has_attribute($attribute) {
    $object_vars = $this->attributes();

    return array_key_exists($attribute, $object_vars);
  }

  protected function attributes() {
    $attributes = array();

    //this static::$db_fields is where my problem is
    foreach(static::$db_fields as $field) {

      if(property_exists($this, $field)) {
        $attributes[$field] = $this->$field;
      }
    }
    return $attributes;
  }
}

class Personnel extends DatabaseObject {
  protected static $table_name = "personnel";

  //this is the property I am trying to access in DatabaseObject
  protected static $db_fields = array('id', 'username', 'password', 'first_name', 'last_name', 'email', 'permissions');

public static function authenticate($username="", $password="") {
    global $database;
    $username = $database->escape_value($username);
    $password = $database->escape_value($password);

    $sql = "SELECT * FROM " . self::$table_name . " ";
    $sql .= "WHERE username = '{$username}' ";
    $sql .= "AND password = '{$password}' ";
    $sql .= "LIMIT 1";

    $result_array = parent::find_by_sql($sql);
    return !empty($result_array) ? array_shift($result_array) : false;

}
}

The error I get:

Fatal error: Access to undeclared static property: DatabaseObject::$db_fields
  • 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-04T15:10:13+00:00Added an answer on June 4, 2026 at 3:10 pm

    Works fine for me. The error sounds like you have a DatabaseObject instance instead of a Personnel instance.

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

Sidebar

Related Questions

I'm trying to learn how to use WinForms databinding, but one thing that's confusing
I am trying to learn how to use the AsyncTask class to authenticate the
I trying to learn how to use Java Swing's GroupLayout. First of all I
I am trying to learn and use an SDK for a vendor's product. Unfortunately,
I am trying to learn to use buffer overflow attack in Ubuntu. Unfortunately, I
I am trying to learn to use the wx packages to make GUI programs
I am relatively new to programming, and I am trying to learn to use
I'm trying to learn how to use oop in php. I'm also fairly new
I'm trying to learn how to use lift. I can create project skeleton by
I'm trying to learn how to use actionscript over mxml for flexibility. I have

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.