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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:18:12+00:00 2026-05-13T08:18:12+00:00

I have two classes: abstract Entity , abstract ClassA extends Entity , ClassB extends

  • 0

I have two classes:

abstract Entity, abstract ClassA extends Entity, ClassB extends ClassA

Entity is an generic class for all kinds of entities, such as Cars or Students. There is an static class variable called $_entity_name, which contains the exact class name of the entity in the ER diagram.

The big problem: Entity can’t set the value of this variable, but uses it! So I must define it in Entity, but I can’t redefine it in ClassA.

ClassA is the auto-generated base class of an special ORM entity (lets say “Student”). The user is supposed to subclass this base class to add his own business logic.

ClassB is created by the user and extends ClassA. That’s the place where he adds his business logic. He’s not supposed to touch $_entity_name or set this value.

The only way I see is this:

ClassA defines an init() method which initializes these “system level” instance variables to reasonable values.

I want the user to not have to think at all about calling anything which is unusual. I don’t know if it’s usual in PHP to explicitely also call the constructor of the parent class, or not. But I guess it isn’t.

Questions:
A) What’s the most convenient way to call init() after instantiation of the class?
B) Is there a way to achieve that in such a way, that the user who creates ClassB must not think at all about calling init()?
C) What other options do I have?

  • 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-13T08:18:13+00:00Added an answer on May 13, 2026 at 8:18 am

    Not exactly an answer to your question but maybe a solution for your problem:
    Instead of having a property containing the actual class name (that’s what you wanted, isn’t it?) you can use get_called_class() (as of php 5.3.0) to get the name of the class for which the static function has been called.

     class Entity {
       public static function foo() {
         echo 'name=', get_called_class(), "\n";
       }
     }
    
     class ClassA extends Entity { }
     class ClassB extends ClassA { }
    
     Entity::foo();
     ClassA::foo();
     ClassB::foo();
    

    prints

     name=Entity
     name=ClassA
     name=ClassB
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 317k
  • Answers 317k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This solution should work, but I'd recommend mutexes over critical… May 13, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Did you mean this: bash$ VARIABLE=3 bash$ sed "${VARIABLE}d" filename… May 13, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Your problem is that this line is constructing a nameless… May 13, 2026 at 11:45 pm

Related Questions

Imagine that I have a Debtor class. With Hibernate, I will define the class
I know this should be a pretty elementary issue to fix, but 1) I'm
I have two classes A and B, where B is subclass of A and
I have two classes, Person and Company, derived from another class Contact. They are
I have two classes one of which inherits from the other. Im trying to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.