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 :



 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' =>


        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

People are also looking for solutions to the problem: php - Getting data from Yelp API


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.