Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-221

ClassLoader breaks when className starts with \

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      The ClassLoader seems to ignore classNames that start with "\".

      When it is instantiated in tools/sandbox/doctrine.php with a parameter instead of for the global namespace, it does not find "\Doctrine\Common\Cli\Tasks\HelpTask" (but finds all classes that start with "Doctrine"). To reproduce, change this line in tools/sandbox/doctrine.php

      $classLoader = new \Doctrine\Common\ClassLoader();

      to

      $classLoader = new \Doctrine\Common\ClassLoader('Doctrine');

      The script fails now:
      PHP Fatal error: Class '\Doctrine\Common\Cli\Tasks\HelpTask' not found in /home/kaiser/doctrine/doctrine/lib/Doctrine/Common/Cli/TaskNamespace.php on line 81

      Registering the ClassLoader only for some specific namespaces (e.g. "Doctrine", "Entities", "Proxies") is vital for inclusion in an existing Zend autoloading environment...

        Activity

        Hide
        Nico Kaiser added a comment -

        ... or will the "IsolatedClassLoader" be the one to use for such environments?

        Show
        Nico Kaiser added a comment - ... or will the "IsolatedClassLoader" be the one to use for such environments?
        Hide
        Nico Kaiser added a comment -

        The same happens when I change doctrine.php to use the IsolatedClassLoader:

        <?php
        
        require_once __DIR__ . '/../../lib/Doctrine/Common/IsolatedClassLoader.php';
        
        $classLoader = new \Doctrine\Common\IsolatedClassLoader('Doctrine');
        $classLoader->setBasePath(__DIR__ . '/../../lib');
        $classLoader->register();
        
        // Variable $configuration is defined inside cli-config.php
        require_once __DIR__ . '/cli-config.php';
        
        $cli = new \Doctrine\Common\Cli\CliController($configuration);
        $cli->run($_SERVER['argv']);
        
        
        Show
        Nico Kaiser added a comment - The same happens when I change doctrine.php to use the IsolatedClassLoader: <?php require_once __DIR__ . '/../../lib/Doctrine/Common/IsolatedClassLoader.php'; $classLoader = new \Doctrine\Common\IsolatedClassLoader('Doctrine'); $classLoader->setBasePath(__DIR__ . '/../../lib'); $classLoader->register(); // Variable $configuration is defined inside cli-config.php require_once __DIR__ . '/cli-config.php'; $cli = new \Doctrine\Common\Cli\CliController($configuration); $cli->run($_SERVER['argv']);
        Hide
        Roman S. Borschel added a comment -

        This sounds like it was caused by the recent CLI refactorings.

        A class name passed to a class loader should never start with a backslash, class names in strings are always fully-qualified, hence the leading backslash is senseless.

        So I am curious as to where/why the class loader gets "\Doctrine\Common\Cli\Tasks\HelpTask" instead of "Doctrine\Common\Cli\Tasks\HelpTask".

        I'm sure this is caused by the new CLI code.

        Show
        Roman S. Borschel added a comment - This sounds like it was caused by the recent CLI refactorings. A class name passed to a class loader should never start with a backslash, class names in strings are always fully-qualified, hence the leading backslash is senseless. So I am curious as to where/why the class loader gets "\Doctrine\Common\Cli\Tasks\HelpTask" instead of "Doctrine\Common\Cli\Tasks\HelpTask". I'm sure this is caused by the new CLI code.
        Hide
        Roman S. Borschel added a comment -

        This should be fixed now. However, the CLI does still not work well. Just tested "doctrine orm:schema-tool --create" and it quits with a "Fatal error: Call to undefined method Doctrine\ORM\Tools\Cli\Tasks\SchemaToolTask::getEntityManager() in /Users/robo/dev/php/Doctrine/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php on line 144"

        Show
        Roman S. Borschel added a comment - This should be fixed now. However, the CLI does still not work well. Just tested "doctrine orm:schema-tool --create" and it quits with a "Fatal error: Call to undefined method Doctrine\ORM\Tools\Cli\Tasks\SchemaToolTask::getEntityManager() in /Users/robo/dev/php/Doctrine/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php on line 144"
        Hide
        Roman S. Borschel added a comment -

        Ok, this is now fixed, too. Guilherme is working on some improvements.

        The CLI should work now but it does currently not recognize the $globalArguments. Thats why you will probably need to specify the --class-dir on the CLI manually currently.

        Show
        Roman S. Borschel added a comment - Ok, this is now fixed, too. Guilherme is working on some improvements. The CLI should work now but it does currently not recognize the $globalArguments. Thats why you will probably need to specify the --class-dir on the CLI manually currently.
        Hide
        Roman S. Borschel added a comment -

        I'll mark this one as resolved and open a new issue for Guilherme concerning the global CLI arguments.

        If this issue is not fixed for you feel free to reopen.

        Show
        Roman S. Borschel added a comment - I'll mark this one as resolved and open a new issue for Guilherme concerning the global CLI arguments. If this issue is not fixed for you feel free to reopen.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Nico Kaiser
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: