CodeIgniter Forums
Undefined property: stdClass::$userNAME and Undefined index: userNAME - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Undefined property: stdClass::$userNAME and Undefined index: userNAME (/showthread.php?tid=75848)



Undefined property: stdClass::$userNAME and Undefined index: userNAME - owino - 03-23-2020

I am pulling information from a database that arrive with one field named userNAME. I am using $query->getResultObject()[see https://codeigniter4.github.io/userguide/database/results.html#result-arrays] therefore giving me an array of objects. The data in this field is a ';' separated list which I am processing into an array and storing back in the field of the object holding an element of the result array.

In the end what I have is $Object->userNAME as an array with a number of keys, one of them 'full'; So to access a full name, I use 
$Object->userNAME['full'];

This has been working for me for years in CI3. I am moving to CI4 and the trouble is that now in CI4 I get the error
Undefined property: stdClass::$userNAME
when I issue
$Object->userNAME['full'];

I assumed the problem was Object so I converted all operations to Array, thus accessing full name now becomes
$Object['userNAME']['full'];
only to meet the error
Undefined index: userNAME

Some two strange observations to me
1. When I issue 
echo $Object['userNAME']['full'];
or 
echo $Object->userNAME['full'];
I get the error Undefined index: userNAME and Undefined property: stdClass::$userNAME respectively but still get the expected output!

2. With the array usage, I get the output 1 and the full name but with the warning when I issue the following!
echo array_key_exists ('userNAME' , $Object ); //output is 1
$Object['userNAME']['full']; //output is a full name and also error message

I am stuck, please help.


RE: Undefined property: stdClass::$userNAME and Undefined index: userNAME - includebeer - 03-24-2020

Why don’t you just dump the whole object to see what it contains? Then you will see what’s wrong...


RE: Undefined property: stdClass::$userNAME and Undefined index: userNAME - owino - 03-25-2020

For the time being, I am making do with @$Object['userNAME']['full'] which is working.

I hope to investigate this later.