如何从子类中获取值作为主范围内的受保护 ststic 属性。我在这些行中使用,但它不起作用。
self::$table_name="Table_shape_B";
self::$table_name="Table_shape_C";
我想看看这些线谢谢。
selected Database Table name: Table_shape_B
selected Database Table name: Table_shape_C
输出是
new B : are created :
new C : are created :
selected Database Table name:
selected Database Table name:
这是我的代码:
<?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();
?>