php - how to use an static var from child class in its parent class with an static method -


i want value of static var redeclared in subclass :

    class {          private static $echo_var = 'parent_echo' ;          public static function e() {             return '$echo_var = ' . self::$echo_var ;         }     }      class b extends {          private static $echo_var = 'child_echo';     }      echo b::e(); 

i want child_echo.

thanks, mottenmann

use static keyword when accesing it:

return '$echo_var = ' . static::$echo_var ; 

it's called late static binding. won't work on private members. you'll have make public or protected. private properties accessible in class in defined.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -