Call to undefined method Closure::getName()
<h2>Background</h2>

<p>I have a project that I am working on, and it uses Doctrine 2. I have created the entities, defined the relationships, put test data in the database and am in the testing portion of it. I am not new to Doctrine (because of using Symfony framework), but I am new to using the Doctrine component on it's own -- which is what this is. I don't know if that has any bearing, but I want to make it clear this isn't a Symfony project.</p>

<h2>Entities</h2>

<p><strong>Interest</strong></p>

<pre><code>/**
 * Class Interest
 * @ORM\Entity()
 * @ORM\Table(name="interest", uniqueConstraints={
 *   @ORM\UniqueConstraint(name="interest_name", columns={"name"})
 * })
 */
class Interest {
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", unique=TRUE, nullable=FALSE)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string")
     */
    private $description;

    /**
     * @var array
     *
     * @ORM\OneToMany(targetEntity="Subscription", mappedBy="interests", cascade={"persist", "remove"}, orphanRemoval=TRUE)
     */
    private $subscribers;

    public function __construct() {
        $this-&gt;subscribers = new ArrayCollection();
    }
</code></pre>

<p><strong>Subscription</strong></p>

<pre><code>/**
 * Class Subscription
 * @ORM\Entity()
 * @ORM\Table(name="subscription")
 */
class Subscription {
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var array
     *
     * @ORM\ManyToOne(targetEntity="Interest", inversedBy="subscribers")
     * @ORM\JoinColumn(name="interest_id", referencedColumnName="id", nullable=FALSE)
     */
    private $interests;

    /**
     * @var string
     *
     * @ORM\ManyToOne(targetEntity="Subscriber", inversedBy="interests")
     * @ORM\JoinColumn(name="subscriber_id", referencedColumnName="id", nullable=FALSE)
     */
    private $subscriber;

    /**
     * @var string
     *
     * @ORM\Column(name="interest_date", type="datetime")
     */
    private $subscribed_on;

    public function __construct() {
        $this-&gt;subscribed_on = new \DateTime("now");
        $this-&gt;interests = new ArrayCollection();
    }
</code></pre>

<p><strong>Subscriber</strong></p>

<pre><code>/**
 * Class Subscriber
 * @ORM\Entity()
 * @ORM\Table(name="subscriber", uniqueConstraints={
 *   @ORM\UniqueConstraint(name="subscriber_email", columns={"email"})
 * })
 */
class Subscriber {
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="first_name", type="string")
     */
    private $first_name;

    /**
     * @var string
     *
     * @ORM\Column(name="last_name", type="string")
     */
    private $last_name;

    /**
     * @var string
     *
     * @ORM\Column(name="email", type="string", unique=TRUE, nullable=FALSE)
     */
    private $email;

    /**
     * @var array
     * 
     * @ORM\OneToMany(targetEntity="Subscription", mappedBy="subscriber", cascade={"persist", "remove"}, orphanRemoval=TRUE)
     */
    private $interests;

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_subscribed", type="boolean")
     */
    private $is_subscribed;

    public function __construct() {
        $this-&gt;interests = new ArrayCollection();
    }
</code></pre>

<h2>Testing</h2>

<p>Then to test the relationships I am using this simple script:</p>

<pre><code>$subscriptionRepo = $entityManager-&gt;getRepository( 'Subscribr\Entity\Subscription' );
$subscriptions = $subscriptionRepo-&gt;findAll();

foreach ($subscriptions as $subscription) {
    echo sprintf( "-%s\n", $subscription-&gt;getSubscriber()-&gt;getEmail() );
    $interests = $subscription-&gt;getInterests();
    foreach ($interests as $interest) {
        echo sprintf( "--%s\n", $interest-&gt;getName() );
    }
}
</code></pre>

<h2>Question</h2>

<p>The interpreter gets all the way to the inside of the second loop, and fails with this exception:</p>

<pre><code>C:\xampp\htdocs\www\public_html\playground\subscribr&gt;php list_subscriptions.php
-testemail@domain.com
PHP Fatal error:  Call to undefined method Closure::getName() in C:\xampp\htdocs\www\public_html\playground\subscribr\list_subscriptions.php on line 17
PHP Stack trace:
PHP   1. {main}() C:\xampp\htdocs\www\public_html\playground\subscribr\list_subscriptions.php:0
</code></pre>

<p>I've done a bunch of Google searches and SO searches and cant figure out why the <code>Subscriber</code> entity renders the email fine, but the <code>Interest</code> entity returns a <code>Closure</code> instead of an iterable containing the interests. </p>

<p>Am I doing something wrong with my relationships in my annotations? Or am I just not understanding how to make the call to get the interests? I am really stuck here. Any help would be great, please let me know if I can post anything else to make it clearer. Thanks!</p>

<h2>Edit 1</h2>

<p>I made the changes in the relationship so that each subscription can only have one subscriber. When I query the subscription I now get this:</p>

<pre><code>C:\xampp\htdocs\www\public_html\playground\subscribr&gt;php list_subscriptions.php
-testemail@tester.com
--Magazine
-testemail@tester.com
--Newsletter
-testemail@tester.com
--Promotions
-testemail@tester.com
--Email
-testemail2@tester.com
--Magazine
-testemail2@tester.com
--Promotions
-testemail3@tester.com
--Newsletter
-testemail3@tester.com
--Email
-testemail4@tester.com
--Magazine
-testemail4@tester.com
--Promotions
-testemail4@tester.com
--Email
-testemail5@tester.com
--Magazine
-testemail6@tester.com
--Newsletter
-testemail7@tester.com
--Promotions
-testemail9@tester.com
--Promotions
-testemail10@tester.com
--Newsletter
</code></pre>

<p>Now I am curious whether its right to combine them, or if that's the interest and subscriber's job. So <a href="https://stackoverflow.com/questions/40875478/establishing-relationships-through-a-common-table-the-right-way">I'll open another question</a>.</p>