victorjonsson / PHP-Markdown-Documentation-Generator

Write documentation once, and only once!
MIT License
101 stars 32 forks source link

Conflicting Class Names when parsing a directory #2

Open jc21 opened 9 years ago

jc21 commented 9 years ago

Ok I found another one when I was using it on a larger scale app, specifying the parent src directory to parse.

With namespaced classes like:

And then 2 more classes, each using one of the classes above, the generate throws the following error:

PHP Fatal error: Cannot use jc21\Model\Candidate as Candidate because the name is already in use in /path/to/jc21/Api/Migrate.php on line 12

I assume it's because something weird is happening with reflection?

Let me know if this example isn't clear enough.

victorjonsson commented 9 years ago

How does line 12 in jc21/Api/Migrate.php look like?

jc21 commented 9 years ago
12: use jc21\Model\Candidate;
victorjonsson commented 9 years ago

Then you have to change one of your use statements. In the file Migrate.php you could refactor the use of Candidate. Change to:

use jc21\Model\Candidate as ModelCandidate;

You also need to change all references from Candidate to ModelCandidate in the same file.

Would this be a possible solution for you?

jc21 commented 9 years ago

Not really. Having unique class names across multiple files kind of defeats the purpose of scopes.

If it's too hard then don't worry :)

victorjonsson commented 9 years ago

But I don't think that the name clashing has anything to do with this command line tool. It's your code in Migrate.php that uses both Api\Candidate and Model\Candidate which forces you to do import X as Y so that the PHP-interpreter will be able to distinguish between the two Candidates .... However, I'm not sure this is the case so I will do some investigating.

btw, is it possible to get a stack trace?

jc21 commented 9 years ago

Oh I may have not been clear. In Migrate.php there is only one reference to Candidate class, which is the one on line 12. The command line tool is failing because it's trying to "use" the Candidate scope but it's already got a Candidate scope from a previous class it has processed.

src/jc21/Api/Candidate.php

<?php
namespace jc21\Api;

class Candidate {
    // ...
}

src/jc21/Model/Candidate.php

<?php
namespace jc21\Model;

class Candidate {
    // ...
}

src/Console/Migrate.php

<?php
namespace Console;

use jc21\Model\Candidate;

class Migrate {
    // ...
}

src/Console/Migrate2.php

<?php
namespace Console;

use jc21\Api\Candidate;

class Migrate2 {
    // ...
}

I'll get you a trace tomorrow.