Odd Symfony behavior with authenticated anonymous user

Requests for new symfony features.

Odd Symfony behavior with authenticated anonymous user

Postby thorinkor » Tue May 21, 2013 8:58 am

Hi folks.

I've found a very odd Symfony behavior and I got a feeling, that I must share with it. Let's look at this example:
Code: Select all
$user = $this->get('security.context')->getToken()->getUser();

Everything looks ok, BUT.. it has at least three diffrent cases:
1. The method returns User Entity Object when user authenticated with role - fine
2. The method returns NULL if the user is not authenticated (not logged, not anonymous) - fine

3. The method returns A STRING "anon.", when user is authenticated annonymously, but not logged - WTF?!


How can one method return an object, a string or NULL depending on user authentication? I believe this is very bad solution, it's confusing and it's againt good practicies and principles.

I believe the method getUser() should always return NULL or Object only, never a string. In the 3. case it could return for e.g. Annonymous User Object or something like that, but not a string!
thorinkor
Junior Member
 
Posts: 24
Joined: Tue Feb 21, 2012 12:08 pm

Return to Feature requests

Who is online

Users browsing this forum: No registered users and 1 guest