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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:20:41+00:00 2026-06-03T10:20:41+00:00

How can i get the value frome child class as a protected ststic attribute

  • 0

How can i get the value frome child class as a protected ststic attribute in the main scope.
I use in these lines but it doesn’t work.

self::$table_name="Table_shape_B";
self::$table_name="Table_shape_C";

I want to see these lines Thanks.

selected Database Table name: Table_shape_B
selected Database Table name: Table_shape_C

the output are

new B : are created :
new C : are created :
selected Database Table name:
selected Database Table name:

Here my code:

<?php
    abstract class Class_A {

      protected static $table_name;
         //Class_B Database Table name =  "Table_shape_B"
         //Class_CA Database Table name =  "Table_shape_C"
        public function __construct()   {
            echo "<br />"." new ".get_class($this)." : are created :";
        }

        public function get_table_name_protected() {
            return self::$table_name;
        }
    }

    class B extends Class_A {
        //self::$table_name="Table_shape_B";
    }

    class C extends Class_A     {
     //self::$table_name="Table_shape_C";
    }

    $NewObject1= new B ( );
    $NewObject2= new C ( );

    echo "<br />".' selected Database Table name: '.$NewObject1->get_table_name_protected();
    echo "<br />".' selected Database Table name: '.$NewObject2->get_table_name_protected();

 ?>
  • 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-03T10:20:42+00:00Added an answer on June 3, 2026 at 10:20 am

    see http://docs.php.net/language.oop5.late-static-bindings

    As of PHP 5.3.0, PHP implements a feature called late static bindings which can be used to reference the called class in a context of static inheritance. […] “Late binding” comes from the fact that static:: will not be resolved using the class where the method is defined but it will rather be computed using runtime information. It was also called a “static binding” as it can be used for (but is not limited to) static method calls.

    Unfortunately you can’t “force” a subclass to define this static member like you can with abstract member methods.

    <?php
    abstract class Class_A {
    
        public function __construct()   {
            echo get_class($this), "\n";
        }
    
        public function get_table_name_protected() {
            return static::$table_name;
        }
    }
    
    class B extends Class_A {
        protected static $table_name="Table_shape_B";
    }
    
    class C extends Class_A     {
        protected static $table_name="Table_shape_C";
    }
    
    $NewObject1= new B ( );
    $NewObject2= new C ( );
    
    echo $NewObject1->get_table_name_protected(), "\n";
    echo $NewObject2->get_table_name_protected(), "\n";
    

    prints

    B
    C
    Table_shape_B
    Table_shape_C
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get the text value from an elements's child? Say I have
In Python I can use get method to get value from an dictionary without
How can I get the child-input value; from click event on its parent div-
How can I get a value from a preprocess function to template.php, in a
How can I get the int value from a string such as 423e -
How can I get DateTime value in C# from row, the current code is
How can I get the value of title1 from this string in a datatable
How can I get the connection.connection_string value from the following hibernate xml file using
How can I get the selected text (not the selected value) from a drop-down
say I have these models: class Parent(models.Model): slug = models.SlugField() class Child(models.Model): slug =

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.