मैं एक PHP फ़ाइल मैं उपयोग कर रहा हूँ के साथ एक समस्या है, और मैं एक समाधान खोजने के लिए प्रतीत नहीं कर सकते हैं।
कोड में से एक भाग में $this->value
के लिए मूल्य तय करना होगा और मान सही ढंग से मेरी परीक्षण के अनुसार निर्धारित है।
हालांकि, बाद में एक ही कोड में $this->value
खाली है।
कोड यह रहा:
<?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;
}
}
?>
शीर्ष पर function __construct
में, मूल्य सेट कर दिया जाता है, और मैं पुष्टि की है कि ऐसा होता है।
हालांकि, नीचे समारोह function __toString
में, $this->value
खाली है।
कोई विचार यह क्या हो सकता है?
संपादित
तो, संक्षेप में, $ this-> मूल्य ठीक से __construct समारोह में सेट है, लेकिन __toString समारोह में खाली है।
संपादित 2
मैं भी उल्लेख करना चाहिए कि अन्य चर कि __construct समारोह में सेट कर रहे हैं __toString समारोह में काम कर रहे हैं, $ 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)',
'The advertisement will be posted at the side bar.'
),
new Padd_Input_Advertisement(
PADD_NAME_SPACE . '_ads_125125_3',
'Square Ad 3 (125x125)',
'The advertisement will be posted at the side bar.'
),
new Padd_Input_Advertisement(
PADD_NAME_SPACE . '_ads_125125_4',
'Square Ad 4 (125x125)',
'The advertisement will be posted at the side bar.'
),
);
'__toString मूल्यांकन करने के लिए कोशिश कर रहा है' php में एक जादू विधि है क्या आप इसे किसी अन्य नाम में बदल सकते हैं और कोशिश कर सकते हैं? – coolguy
खाली कैसे? 'Var_dump'' __toString' के अंदर क्या कहता है? – Ryan
ठीक है, मैंने मूल्यों को एक .txt फ़ाइल में आउटपुट करने के लिए कुछ कोड डाला है।कोड के शीर्ष पर फ़ाइल के उचित मूल्य को फ़ाइल के नीचे लिखा गया था, केवल एक खाली फ़ाइल लिखी गई थी। –