Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:20:32+00:00 2026-06-11T00:20:32+00:00

I have simple UserInterface entity: function getRoles() { return $this->roles->toArray(); } and with many

  • 0

I have simple UserInterface entity:

function getRoles()
{
    return $this->roles->toArray();
}

and with many to many relation with Role Entity interface

/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"})
*/
protected $roles;

When I try to manage user roles with form Type

public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('roles');
}

Symfony returns me an error:

Expected argument of type “Doctrine\Common\Collections\Collection”,
“array” given

I know the error is in the getRoles method of the entity User that returns an array but I also know getRoles is a method of the interface and must return an array!

Anyone have a good solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:20:34+00:00Added an answer on June 11, 2026 at 12:20 am

    You have two getRoles functions:

    • One is the function for the UserInterface interface which returns a list of Roles
    • The other is the getter for your $roles property

    Since both functions cannot be called the same and they cannot be the same function because they need to return different types, and since the first function needs to follow the interface I suggest you change the name of the second function. Since this needs to reflect the name of the property, you should change this name.

    So, you need to do something like:

    /**
     * @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"})
     */
    protected $userRoles;
    
    /* interface */
    
    function getRoles()
    {
        return $this->userRoles->toArray();
    }
    
    /*getter*/
    
    function getUserRoles() {
        return $this->userRoles;
    }
    

    and then

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('userRoles');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going to make a simple Alarm Clock, I have user interface and
I have built a simple webpage as the frontend user interface for users to
I have simple Javascript code, similar to this one: var mouseIsDown = false; ...
Say that I have simple command line application, that looks something like this #
I have a simple cocoa user interface with a list of items and a
I have little experience with CSS so this might be a very simple problem.
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple class with width and height member fields which define number of
I have simple php validation form that is halfway working. If you leave the
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.