8000 ClassGenerator: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING) · Issue #81 · zendframework/zend-code · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

ClassGenerator: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING) #81

Closed
alex-sainer opened this issue Jun 30, 2016 · 1 comment
Assignees

Comments

@alex-sainer
Copy link
alex-sainer commented Jun 30, 2016

Hi @veewee ,

there is an error within this fix: 4a6f4ab

if ClassNames with leading Backslash are used (i.E. \My\Base\Class), the returnvalue of the Method Zend\Code\Generator\ClassGenerator::generateShortOrCompleteClassname() will be \My\Base\Class

as a quickfix i would suggest something like following:

private function generateShortOrCompleteClassname($fqnClassName)
    {
        $parts = explode('\\', $fqnClassName);
        $parts = array_filter($parts);
        $className = array_pop($parts);
        $classNamespace = implode('\\', $parts);
        $currentNamespace = (string) $this->getNamespaceName();

        if ($classNamespace === $currentNamespace || in_array($fqnClassName, $this->getUses())) {
            return $className;
        }

        return '\\' . $fqnClassName;
    }

see the "array_filter()" method after explode

@Ocramius
Copy link
Member

Duplicate of #75

@Ocramius Ocramius self-assigned this Jun 30, 2016
weierophinney added a commit that referenced this issue Jun 30, 2016
Close #75
Fixes #74
Fixes #80
Fixes #81
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants
0