Skip to content

Loading…

DDC-221: ClassLoader breaks when className starts with \ #2906

Closed
doctrinebot opened this Issue · 7 comments

1 participant

@doctrinebot

Jira issue originally created by user nicokaiser:

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...

@doctrinebot

Comment created by nicokaiser:

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

@doctrinebot

Comment created by nicokaiser:

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']);

@doctrinebot

Comment created by romanb:

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.

@doctrinebot

Comment created by romanb:

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"

@doctrinebot

Comment created by romanb:

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.

@doctrinebot

Comment created by romanb:

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.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-ALPHA4 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.