मुझे पूरा यकीन नहीं है कि यह क्यों हो रहा है, या इसे सही ढंग से कैसे समझाया जाए, लेकिन शायद कोई इस पर कुछ प्रकाश डाल सकता है।पुन: असाइन किए जाने तक परिवर्तनीय खाली
मेरे पास एक रजिस्ट्री, नियंत्रक और मॉड्यूल का उपयोग करने वाले कोडइग्निटर/ओपनकार्ट फ्रेमवर्क के आधार पर एक सीएमएस सिस्टम है। ..
echo empty($this->application_page)?'yes':'no';
//Returns Yes
लेकिन जब मैं पुन: असाइन करें:
$this->application_page = 'current/page';
लेकिन किसी कारण जब मैं आवेदन में इसे कहते के लिए: मैं एक परिदृश्य में जहाँ मैं पहले के रूप में रजिस्ट्री करने के लिए एक चर बचाया है में चलाने की है यह:
echo empty($this->application_page)?'yes':'no';
//Returns Yes
$page = $this->application_page;
echo empty($page)?'yes':'no';
//Returns No
एक var_dump रिटर्न:
var_dump($this->application_page);
string 'current/page' (length=12)
मैं $page
का उपयोग कर इसे आसानी से प्राप्त कर सकता हूं लेकिन मुझे यह जानकर उत्सुकता है कि यह क्यों हो रहा है?
अद्यतन:
तो मैं _isset
समारोह के साथ चारों ओर गड़बड़ लेकिन यह काम करने के लिए, संभवतः मेरी त्रुटि, संभवतः नहीं नहीं मिला .. यहाँ यह सब कैसे काम करता है:
class Registry {
private $data = array();
public function get($key){ return (isset($this->data[$key]) ? $this->data[$key] : NULL); }
public function set($key,$val){ $this->data[$key] = $val;
}
abstract class Controller {
protected $registry;
public function __construct($registry){ $this->registry = $registry; }
public function __get($key){ return $this->registry->get($key); }
public function __set($key,$value){ $this->registry->set($key, $value); }
}
class Applications {
private $registry;
function __construct($Registry){ $this->registry = $Registry; }
function __get($key){ return $this->registry->get($key); }
function __set($key,$val){ return $this->registry->set($key,$val); }
public function buildApplication(){
$this->application_page = 'current/page';
$application = new application($this->registry);
}
}
class Application extends Controller {
public function index(){
echo empty($this->application_page)?'yes':'no';
//Returns Yes
$page = $this->application_page;
echo empty($page)?'yes':'no';
//Returns No
}
}
उम्मीद है कि इससे मदद मिलती है? एक टाइपो था, रजिस्ट्री के कार्य जादू तरीके नहीं हैं। एप्लिकेशन में $ रजिस्ट्री भी घोषित की गई थी।
क्या आप 100% सुनिश्चित हैं कि इसका परीक्षण करते समय आपके पास अलग-अलग नाम नहीं हैं? – NDM
देरी के बारे में क्षमा करें! हां, मुझे यकीन है, मैंने पोस्ट करने से पहले लगभग 5 बार चेक किया है =) – Corey
@Corey कृपया मेरा अपडेट किया गया जवाब देखें। – ComFreek