我发现了一个扩展抽象父类的子类的奇怪问题。
我这样称呼我的孩子班:
$atts['ad_name'] = 'Test';
$atts['ad_type'] = $_REQUEST['ad_type'];
$add_ad = new wpam_ad_form( $atts );
我的子构造函数看起来像这样:
public function __construct( $atts ) {
parent::__construct( $atts );
echo "<br/><br/>New window child: " . $this->ad_new_window;
echo "<br/>Ad Name child: " . $this->ad_name;
}
我的(简化的)父构造函数如下所示:
$this->ad_type = $atts['ad_type'];
$this->ad_name = stripslashes_deep( $atts['ad_name'] );
$this->ad_content = stripslashes_deep( $atts['ad_content'] );
$this->ad_image = $atts['ad_image'];
$this->ad_url = $atts['ad_url'];
$this->ad_prehtml = stripslashes_deep( $atts['ad_prehtml'] );
$this->ad_posthtml = stripslashes_deep( $atts['ad_posthtml'] );
$this->ad_new_window = ( $atts['ad_new_window'] != "" ? $atts['ad_new_window'] : 1 );
$this->ad_active = ( $atts['ad_active'] != "" ? $atts['ad_active'] : 1 );
$this->ad_archived = 0;
$this->ad_checked = 0;
echo "<br/>New window parent: " . $this->ad_new_window;
echo "<br/>Ad name parent: " . $this->ad_name;
这些回声的输出给了我:
New window parent: 1
Ad name parent: Test
New window child:
Ad Name child:
我以前从未见过这种情况。这些值被正确地传递到子构造函数和父构造函数中。父构造函数正在正确设置值。然后在父构造函数运行后,子构造函数的 $this 属性中没有值。是什么导致值没有从父类返回到子类?