At first look, this snippet seems to be fine.
// my_controller.php
$data['errors'] = (object)$this->session->userdata('errors_registration');
$this->load->view('registration/my_view',$data);
// print_r($data['errors'])
// stdClass Object
// (
// [domain_err] => 0
// [wbholder_err] => 0
// [methodpayment_err] => 0
// [createaccount_err] => 2
// [gtc_err] => 0
// )
// my_view.php
if($errors->domain_err == 1) echo "TRUE"; else echo "FALSE"; // FALSE
And when, $data['errors'] is empty,
// print_r($data['errors'])
// stdClass Object
// (
// [scalar] =>
// )
// my_view.php
if($errors->domain_err == 1) echo "TRUE"; else echo "FALSE";
I get this,
A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$domain_err
To address the notice, I added isset(), making my snippet now to if(isset($errors->domain_err) == 1), however, since this change, the condition seems to be always set to true, thus outputting TRUE. Is there other way around to get over the notice while maintaining the conditional output I am expecting?
The reason for it always being true, is because you are comparing it now to what the function returns, which is true because $errors->domain_err is set. What you need to do is change the condition to:
if(isset($errors->domain_err) && $errors->domain_err == 1)
isset does not return the value of the variable, just whether it exists or not.