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

  • Home
  • SEARCH
  • 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 6555813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:51:57+00:00 2026-05-25T12:51:57+00:00

I have a php abstract generic class with several static variables and functions. class

  • 0

I have a php abstract generic class with several static variables and functions.

class Generic{
    public static $ID;
    private static $tableName;
    private static $oldTableName;
    protected static $DAL;

    public static function Init($tableName, $id=null)    {

        if(self::$tableName)
            self::$oldTableName=self::$tableName;

        self::$tableName=$tableName;        

        self::$DAL = new DAL(self::$tableName);
    }

    public static function RecallTableName(){
        if(self::$oldTableName){
            self::$tableName=self::$oldTableName;
            self::$oldTableName=null;
            return true;
        }
    }

    public static function GetProperty($id, $columnName, $whereStatement = "1=1"){
        if(!self::$tableName)
            return false;

        //DO DB STUFF HERE

        return; //RETURN WHAT DB CALLS DID HERE
    }
}

Several classes inherit from this generic class using extends.

class Part extends Generic {

    static function  Init($tableName="part",$id = null) {
        $return = parent::Init($tableName,$id);
        new Part();
        return $return;
    }

    public static function destruct(){
        parent::RecallTableName();
    }

    public function __destruct() {
        Part::destruct();
    }

    public static function  GetProperty($id, $columnName, $whereStatement = "1=1") {
        self::Init();
        return parent::GetProperty($id, $columnName, $whereStatement);
    }
}

class System extends Generic {

    static function  Init($tableName="system",$id = null) {
        $return = parent::Init($tableName,$id);
        new System();
        return $return;
    }

    public static function destruct(){
        parent::RecallTableName();
    }

    public function __destruct() {
        Part::destruct();
    }

    public static function GetProperty($id, $columnName, $whereStatement = "1=1") {
        self::Init();
        return parent::GetProperty($id, $columnName, $whereStatement);
    }

    public static function GetInventory($PartManageIDToCheck)
    {
        return Part::GetInventory($PartManageIDToCheck);
    }
}

This way when I implement a method call on a child I can hook on the child’s death. Going further, I can call:

System::GetInventory(1)

This will:
1 – Call Init() on Generic which stores “system” in the Generic::$tableName.
2 – Cenerate a nested sibling (Part) which in turn calls Init() on Generic which then moves Generic::$tableNameto Generic::$oldTableNameand stores “part in Generic::$tableName

This all works without issue. However, when I use two children back to back it falls apart.

System::GetProperty(1, "ID");
Part::GetProperty(3, "ID");

Using the two back to back allows Generic to persist somehow so that Generic::$tableName == "system" when Part::GetProperty(3, "ID"); gets called.

Any idea how to fix this?

  • 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-25T12:51:57+00:00Added an answer on May 25, 2026 at 12:51 pm

    What you’re looking for is late static binding which was added in PHP 5.3. Change the definition of $tableName to protected static $tableName. Then redeclare it exactly the same way in each child class.

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

Sidebar

Related Questions

I have an abstract data mapper class: <?php abstract class ADataMapper { abstract public
I have a class like: <?PHP abstract class dbCon { public function OpenConnection() {
I have the following class: <?php /* * Abstract class that, when subclassed, allows
I have created this file at My/View/Helper/FormElement.php <?php abstract class My_View_Helper_FormElement extends Zend_View_Helper_FormElement {
I have several static factory patterns in my PHP library. However, memory footprint is
I have a problem with the following piece of PHP script: <?php abstract class
<?php abstract class AbstractClass { public function __get($theName) { return (isset($this->$theName)) ? $this->$theName :
I have an abstract class that wraps PHP exception: abstract class MyException extends Exception
I have the following class: abstract class TheView { public $template = NULL; public
I've following abstract class and have a question about how to write a unit

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.