Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hotfix - FQCN in `extends` and `implements` #4151

Closed
wants to merge 2 commits into from

2 participants

@Ocramius
Collaborator

This PR is a BC break.

Similar to #4149, it is currently problematic to generate multiple classes into the same file.

This PR introduces fully qualified class names for the extends and implements clauses in generated code.

Before

class Foo extends Bar implements Baz {}

After

class Foo extends \Bar implements \Baz {}
@weierophinney

Just like my comment to #4149, I think this behavior needs to be opt-in, and not the default.

@Ocramius
Collaborator

Closing: this PR introduces a BC break and I need to think of it (or find the time to think of it) before asking for merge.

@Ocramius Ocramius closed this
@Ocramius Ocramius deleted the Ocramius:hotfix/fqcn-class-extends-implements branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 library/Zend/Code/Generator/ClassGenerator.php
@@ -697,11 +697,16 @@ public function generate()
$output .= 'class ' . $this->getName();
if (!empty($this->extendedClass)) {
- $output .= ' extends ' . $this->extendedClass;
+ $output .= ' extends \\' . trim($this->extendedClass, '\\');
}
$implemented = $this->getImplementedInterfaces();
+
if (!empty($implemented)) {
+ foreach ($implemented as & $interface) {
+ $interface = '\\' . trim($interface, '\\');
+ }
+
$output .= ' implements ' . implode(', ', $implemented);
}
View
12 tests/ZendTest/Code/Generator/ClassGeneratorTest.php
@@ -200,7 +200,7 @@ public function testToString()
));
$expectedOutput = <<<EOS
-abstract class SampleClass extends ExtendedClassName implements Iterator, Traversable
+abstract class SampleClass extends \ExtendedClassName implements \Iterator, \Traversable
{
public \$foo = null;
@@ -233,8 +233,8 @@ public function testClassFromReflectionThatImplementsInterfaces()
$code = $classGenerator->generate();
$expectedClassDef = 'class ClassWithInterface'
- . ' implements ZendTest\Code\Generator\TestAsset\OneInterface'
- . ', ZendTest\Code\Generator\TestAsset\TwoInterface';
+ . ' implements \ZendTest\Code\Generator\TestAsset\OneInterface'
+ . ', \ZendTest\Code\Generator\TestAsset\TwoInterface';
$this->assertContains($expectedClassDef, $code);
}
@@ -251,8 +251,8 @@ public function testClassFromReflectionDiscardParentImplementedInterfaces()
$code = $classGenerator->generate();
$expectedClassDef = 'class NewClassWithInterface'
- . ' extends ZendTest\Code\Generator\TestAsset\ClassWithInterface'
- . ' implements ZendTest\Code\Generator\TestAsset\ThreeInterface';
+ . ' extends \ZendTest\Code\Generator\TestAsset\ClassWithInterface'
+ . ' implements \ZendTest\Code\Generator\TestAsset\ThreeInterface';
$this->assertContains($expectedClassDef, $code);
}
@@ -288,7 +288,7 @@ public function testSetextendedclassShouldNotIgnoreNonEmptyClassnameOnGenerate()
->setExtendedClass('ParentClass');
$expected = <<<CODE
-class MyClass extends ParentClass
+class MyClass extends \ParentClass
{
View
2  tests/ZendTest/Code/Generator/FileGeneratorTest.php
@@ -66,7 +66,7 @@ public function testToString()
require_once 'SampleClass.php';
-abstract class SampleClass extends ExtendedClassName implements Iterator, Traversable
+abstract class SampleClass extends \ExtendedClassName implements \Iterator, \Traversable
{
Something went wrong with that request. Please try again.