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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:00:17+00:00 2026-05-26T15:00:17+00:00

I have this (shortened): abstract class MyModel { const DBID = ; const TOKEN

  • 0

I have this (shortened):

abstract class MyModel
{
    const DBID = "";
    const TOKEN = "";

    public function getDB()
    {
        if(!$this->_DB)
        {
            $c = get_called_class(); // doesn't work pre php 5.3
            echo $c::DBID; // doesn't work pre php 5.3
            echo $c::TOKEN // doesn't work pre php 5.3
        }

        return $this->_qb;
    } 

The problem is that get_called_class() and the $c::DBID/TOKEN doesn’t work in php < 5.3

Is there a way I can accomplish the same task from within the abstract class that is compatible with 5.2.9?

  • 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-26T15:00:17+00:00Added an answer on May 26, 2026 at 3:00 pm

    EDIT:
    Constants aren’t really meant to be changed throughout object instantiations, you may want to consider member variables instead.

    Abstract classes cannot be instantiated directly. You could create a child class to extend your abstract class, then make the call to getDb().

    abstract class MyModel
    {
        private $dbId;
        private $token;
    
        public function setDbId($dbId)
        {
            $this->dbId = $dbId;
        }
    
        public function setToken($token)
        {
            $this->token = $token;
        }
    
        public function getDbId()
        {
            return $this->dbId;
        }
    
        public function getToken()
        {
            return $this->token;
        }
    
        public function __construct()
        {
            // All child classes will have the same values
            $this->setDbId('myParentDbId');
            $this->setToken('myParentToken');
        }
    
        protected function getDb()
        {
            echo $this->getDbId();
            echo $this->getToken();
        }
    }
    
    class MyChildModel extends MyModel
    {
        // Don't need any methods, just access to abstract parent
        // But if I wanted to override my parent I could do this
        public function __construct()
        {            
            parent::__construct();
    
            $this->setDbId('myChildDbId');
            $this->setToken('myChildToken');
        }
    }
    
    $myChildModel = new MyChildModel();
    var_dump($myChildModel->getDb());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this basic utility class fetches (possibly) shortened URLs in parallel and returns
I had a huge file for creating this GUI and I have shortened it
Consider this code (shortened) function getSecret() { db.transaction( function (transaction) { transaction.executeSql( 'SELECT *
I have a Class, call it X, in this class I have successfully advised
I have this structure: <div class=gBigPage> <span class=gBigMonthShort>FEB</span><br /> <span class=gBigDayShort>23</span><br /> <span class=gBigYearShort>2011</span>
I have this code: @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws
I have this in my package.json file (shortened version): { name: a-module, version: 0.0.1,
I have a simple set of arrays, kind of like this .. structure shortened
I have a class MemoryPool with the following (shortened to relevant) code: namespace System
I have an unordered list of items, something like this, shortened for brevity: <div

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.