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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:24:21+00:00 2026-05-28T08:24:21+00:00

lI am building a light-weight Model layer for my project’s database access. I would

  • 0

lI am building a light-weight Model layer for my project’s database access.
I would like it to be in the spirit of Ruby on Rails. Instead of instantiating a new Model
object, I want to use a singleton approach. Here is the current issue I am facing:

class BaseModel {
    public static $name;
    public static function get($id) {
        echo "SELECT * FROM ". self::$name ."s WHERE ". self::$name .' = '.$id;
    }
}

class Customer extends BaseModel {
    //parent::$name = 'customer'; => ERROR
}

$c = Customer::get(4);

Is there some way to assign the parent’s static members in the class body? I would like
to avoid creating an actual singleton class if possible. 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-05-28T08:24:21+00:00Added an answer on May 28, 2026 at 8:24 am

    The feature you are looking for is called Late Static Binding (LSB) and thankfully has been introduced to PHP in 5.3. You may read about it here: http://php.net/manual/en/language.oop5.late-static-bindings.php

    This is your code rewritten using LSB.

    <?php
    
    class BaseModel {
        public static $name;
        public static function get($id) {
            echo "SELECT * FROM ". static::$name ."s WHERE ". static::$name .' = '.$id;
        }
    }
    
    class Customer extends BaseModel {
        public static $name = 'customer';
    }
    
    $c = Customer::get(4);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an application which has multiple user entry screens. I would like
I am building a Boxee app and would like to, in response to certain
Building the same project (without any changes) produces binary different exe-files: some small regions
I am building an application that is based on MVVM-Light. I am in the
I'm building Rails application and I want to have user registration/login functionality. I also
Building a WP7 app using MVVM light for my view models. I'm using the
I'm building a web page screen capture application for an internal R&D project. Environment:
Building on How Do You Express Binary Literals in Python , I was thinking
Building a client-side swing application what should be notified on a bus (application-wide message
Building on what has been written in SO question Best Singleton Implementation In Java

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.