theseer / Autoload

A lightweight php namespace aware autoload generator and phar archive builder
Other
388 stars 47 forks source link

Incorrect "Redeclaration of class" error #30

Closed sebastianbergmann closed 12 years ago

sebastianbergmann commented 12 years ago
➜  phpcpd git:(master) ✗ ant phpab 
Buildfile: /usr/local/src/phpcpd/build.xml

phpab:
     [exec] phpab 1.7.0 - Copyright (C) 2009 - 2011 by Arne Blankerts
     [exec] 
     [exec] Error while processing request:
     [exec]  - Redeclaration of class 'sebastianbergmann\\phpcpd\\strategy\\abstractstrategy' detected
     [exec]    Original:  /usr/local/src/phpcpd/src/Detector/Strategy/AbstractStrategy.php
     [exec]    Secondary: /usr/local/src/phpcpd/src/Detector/Strategy/Default.php
     [exec] 
     [exec] 
     [exec] Result: 1

BUILD SUCCESSFUL
Total time: 0 seconds

➜  phpcpd git:(master) ✗ grep AbstractStrategy **/*.php
src/Detector/Detector.php:    use SebastianBergmann\PHPCPD\Strategy\AbstractStrategy;
src/Detector/Detector.php:         * @param AbstractStrategy $strategy
src/Detector/Detector.php:        public function __construct(AbstractStrategy $strategy, \ezcConsoleOutput $output = NULL)
src/Detector/Strategy/AbstractStrategy.php:    abstract class AbstractStrategy
src/Detector/Strategy/Default.php:    class Default extends AbstractStrategy
src/Detector/Strategy/SaveMemory.php:    class SaveMemory extends AbstractStrategy

If I change class Default extends AbstractStrategy to just class Default it works.

theseer commented 12 years ago

'Default' is a reserved word and thus not valid for a class name. On the token level it will result in T_DEFAULT rather than a string for the class name. Admittingly though, the error message didn't make any sense.

The code has been changed to be more strict and throw an exception in case an invalid class construction is detected. Fix has been pushed with commit 085d270d170154285bf56ef0a40908bf782007a3 and will be released with the upcoming version.