脚本宝典收集整理的这篇文章主要介绍了php – $this->值输,好吧,它的价值,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
在代码的一部分中,设置$this->值的值,并根据我的测试正确设置该值.
但是,稍后在同一代码中,$this->值为空.
这是代码:
<?PHP class Padd_Input_AdvertiSEMent { PRotected $keyword; protected $value; protected $name; protected $description; function __construct($keyword,$name,$description='') { $this->keyword = $keyword; $this->value = unserialize(get_option($keyword)); $this->name = $name; $this->description = $description; } public function get_keyword() { return $this->keyword; } public function set_keyword($keyword) { $this->keyword = $keyword; } public function get_value() { return $this->value; } public function set_value($value) { $this->value = $value; } public function get_name() { return $this->name; } public function set_name($name) { $this->name = $name; } public function get_description() { return $this->description; } public function set_description($description) { $this->description = $description; } public function __toString() { $strHTML = ''; $strHTML .= '<tr valign="top">'; $strHTML .= ' <th scoPE="row"><label for="' . $this->keyword . '">' . $this->name . '</label></th>'; $strHTML .= ' <td>'; $strHTML .= ' <label for="' . $this->keyword. '_alt_desc">Short Description</label><br />'; $strHTML .= ' <input name="' . $this->keyword . '_alt_desc" type="text" id="' . $this->keyword . '_alt_desc" value="' . $this->value->get_alt_desc() . '" size="80" /><br />'; $strHTML .= ' <label for="' . $this->keyword. '_img_url">Image URL</label><br />'; $strHTML .= ' <input name="' . $this->keyword . '_img_url" type="text" id="' . $this->keyword . '_img_url" value="' . $this->value->get_img_url() . '" size="80" /><br />'; $strHTML .= ' <label for="' . $this->keyword. '_web_url">WebsITe</label><br />'; $strHTML .= ' <input name="' . $this->keyword . '_web_url" type="text" id="' . $this->keyword . '_web_url" value="' . $this->value->get_web_url() . '" size="80" />'; $strHTML .= ' <br /><small>' . $this->description . '</small>'; $strHTML .= ' </td>'; $strHTML .= '</tr>'; return $strHTML; } } ?>
在函数__construct的顶部,设置了值,我确认会发生这种情况.
但是,在底部函数函数__toString中,$this->值为空.
编辑
因此,回顾一下,$this->值在__construct函数中正确设置,但在__toString函数中是空白的.
编辑2
我还应该提到__construct函数中设置的其他变量在__toString函数中工作,就像$this->关键字一样.这是jut $this->值空白.
编辑3
这个类就是这样调用的
$padd_options['advertisements'] = array( new Padd_Input_Advertisement( PADD_NAME_SPACE . '_ads_125125_1','Square Ad 1 (125x125)','The advertisement will be posted at the side bar.' ),new Padd_Input_Advertisement( PADD_NAME_SPACE . '_ads_125125_2','Square Ad 2 (125x125)',new Padd_Input_Advertisement( PADD_NAME_SPACE . '_ads_125125_3','Square Ad 3 (125x125)',new Padd_Input_Advertisement( PADD_NAME_SPACE . '_ads_125125_4','Square Ad 4 (125x125)',);
当您反序列化get_keyword()函数调用的结果时,如果序列化对象的类未知,则PHP将回退到特殊类__PHP_Incomplete_Class_Name.这个类基本上是一个虚拟类:它没有任何方法.但是,它允许您访问反序列化对象的属性.
因此,如果您希望能够调用$this-> value的方法(这是您在__toString中执行的操作),则必须在调用之前包含声明$this->值类型的文件.反序列化.
[edit]您可以查看the PHP manual以获取有关反序列化过程的更多详细信息.
以上是脚本宝典为你收集整理的php – $this->值输,好吧,它的价值全部内容,希望文章能够帮你解决php – $this->值输,好吧,它的价值所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。