<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed Jun 19 08:18:32 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DCOM-75/DCOM-75.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DCOM-75] remove leading backslash from class name before comparing to namespace in annotation autoloading</title>
                <link>http://www.doctrine-project.org/jira/browse/DCOM-75</link>
                <project id="10043" key="DCOM">Doctrine Common</project>
                        <description>&lt;p&gt;I am figuring a problem with Symfony Validator constraints (I use annotations to define the constraint rules).&lt;/p&gt;

&lt;p&gt;As I don&apos;t use Symfony&apos;s framework, I create the validator service by myself.&lt;br/&gt;
Somewhere in its factory, I put the following code:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;         
AnnotationRegistry::registerAutoloadNamespaces(array(
    &apos;\Symfony\Component\Validator\Constraints&apos; =&amp;gt; APPLICATION_ROOT . &apos;/library&apos;
));
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then, in my entities, I have annotations such as:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;use Symfony\Component\Validator\Constraints as Assert;

class Author {
    /**
     * @Assert\NotBlank()
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $name;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In this configuration, I get the following error:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;Semantical Error&amp;#93;&lt;/span&gt; The annotation &quot;@Symfony\Component\Validator\Constraints\NotBlank&quot;&lt;br/&gt;
in property Domain\Entity\Author::$name does not exist, or could not be auto-loaded.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I was able to trace it down to the Doctrine\Common\Annotations\AnnotationRegistry#loadAnnotationClass($class) where we can find the following test:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($class, $namespace) === 0) {
        require ...;
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;which means &quot;if the namespace can be found at the beginning of the FQCN, require it&quot;.&lt;br/&gt;
But those namespaces come from &quot;use&quot; statements where there is no leading backslash.&lt;br/&gt;
That&apos;s why the test fails.&lt;/p&gt;

&lt;p&gt;Christophe Coevoet answered:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;you should remove the leading backslash. Fully qualified class names used as string don&apos;t include it in PHP. &lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Benjamin Eberlei suggested to remove the leading backslash before comparing the class to the namespace.&lt;br/&gt;
I would follow Benjamin suggestion and would like to add a comment about leading backslashes:&lt;/p&gt;

&lt;p&gt;When I add a &lt;tt&gt;use&lt;/tt&gt; statement to my code for a class, I can then use its alias to get an instance of that class.&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;use Doctrine\ORM\Mapping\ClassMetadata;
...
$metadata = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; ClassMetadata();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 
&lt;p&gt;The same is true with:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;use Doctrine\ORM\Mapping as Foo;
...
$metadata = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Foo\ClassMetadata();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;This is not a fully qualified class name&lt;/b&gt;.&lt;br/&gt;
In that sense, I do understand such an annotation: &lt;tt&gt;@ORM\Entity&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;But I find the syntax of a fully-qualified annotation (&lt;tt&gt;@My\Annotation\Whatever&lt;/tt&gt;) erroneous (or at least counter-intuitive) as it doesn&apos;t start with a backslash.&lt;/p&gt;</description>
                <environment>not relevant</environment>
            <key id="13146">DCOM-75</key>
            <summary>remove leading backslash from class name before comparing to namespace in annotation autoloading</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="goriol">Guillaume ORIOL</reporter>
                        <labels>
                    </labels>
                <created>Thu, 3 Nov 2011 15:54:22 +0000</created>
                <updated>Thu, 3 Nov 2011 15:54:22 +0000</updated>
                                    <version>2.1.2</version>
                                                <component>Annotations</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>