code works well while logged in as admin other users dont run

Permalink
Hi
i wrote this ode on a single page and works well when i log in as admin
$u=new \User();
if($u->isRegistered()){
$ui=\UserInfo::getByID($u->getUserID());
$this->myui=$ui;
$color=$ui->getUserFavoriteColor();
$this->set('favorite_color',$color);
}
but when i log in as other created user the page is open but code gives error message says
Call to a member function getUserFavoriteColor() on a non-object

why code runs only with admin !?
thanks in advance.

 
enlil replied on at Permalink Reply
enlil
at first glance, whats with the "\"?

$ui=\UserInfo::getByID($u->getUserID());
macnux replied on at Permalink Reply
this line there is no problem
but very strange thing
i open the page again it works !!!!!
how that happens? i have no idea what going on !!!!
i did not change any thing at ALL
enlil replied on at Permalink Best Answer Reply
enlil
I realize after the fact now, this is 5.7 related. Great that its working now!