php - Duplication visibility attributes Doctrine/Symfony
I'm facing a strange situation using Symfony and Doctrine with a MySql database. I'm French and not that good in english so I will use simple sentences.
Consider this :
-a class called User (implements UserInterface) with some private attributes : username (string), password (string), nom (string), prenom (string), statut (Statut class, useless in this tips) and roles (array of Role)
-a class called Role (implements RoleInterface) with private attributes : role (string representing the name of the role), entrepot (boolean) and roleParent (Role class, I'm using a role hierarchy)
After I mapped my entities and I created some User and Role, I changed the visibility of the attributes of the classes from private to protected (serialization matter with PHP 5.4). Moreover, to be coherent with the RoleInterface, I changed the attribute 'nom' to 'role'.
The problem is :
I log with a user and after that, I want to get the roles through the session. Theoretically, it should work. I get back the User and I apply getRoles method.
But for every Role I have, the name value of the role is null !!
For some reasons, Symfony OR Doctrine OR php has duplicated the attributes and their visibilities.
I'd like to post an image but I don't have enough reputation points.
But what you need to know is that when I make a var_dump on the array of roles of the user, it shows something like this :
array
object
protected 'id' => null<br/>
protected 'role' => null<br/>
protected 'entrepot' => null<br/>
protected 'roleParent' => null<br/>
private'id' => null<br/>
private'nom' => string Value1<br/>
private'entrepot' => boolean false<br/>
private'roleParent' =>
object
protected 'id' => null <br/>
protected 'role' => null <br/>
protected 'entrepot' => null <br/>
protected 'roleParent' => null <br/>
private 'id' => null <br/>
private 'nom' => string Value2<br/>
private 'entrepot' => boolean false<br/>
private 'roleParent' => ....
As you can see, there is a duplication of the attributes. The question is : why ??
I think Doctrine saved the configuration of the class when it did the mapping for the first time.
But even in the database, I have 'role' column and not 'nom' (french word meaning 'name' by the way)
Ask me if you need more details.
Best regards