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

Closed
opened 2026-01-22 12:33:20 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 22, 2009).

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

Originally created by @doctrinebot on GitHub (Dec 22, 2009). 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...
admin added the Bug label 2026-01-22 12:33:20 +01:00
admin closed this issue 2026-01-22 12:33:20 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

Comment created by nicokaiser:

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

@doctrinebot commented on GitHub (Dec 22, 2009): Comment created by nicokaiser: ... or will the "IsolatedClassLoader" be the one to use for such environments?
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

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 commented on GitHub (Dec 22, 2009): 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']); ```
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

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 commented on GitHub (Dec 22, 2009): 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.
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

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 commented on GitHub (Dec 22, 2009): 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"
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

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 commented on GitHub (Dec 22, 2009): 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.
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

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 commented on GitHub (Dec 22, 2009): 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.
Author
Owner

@doctrinebot commented on GitHub (Dec 22, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Dec 22, 2009): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#279