NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
2 classes with same name


Joined: 18 Feb 2011
Posts: 1
Reply with quote
Hello! I discovered the problem when my project have 2 files with classes of same name.
For example...

File f1.php:
Code:
class Foo {
 function s1() {}
}


File f2.php:
Code:
class Foo {
 function s2() {}
}


Classes have the same names, but they have different set of functions, i.e. function s2() is not defined in class of file f1.php. Confused
So... I'm writing this:

File f3.php
Code:
class Bar extends Foo {
 ...
}


I can't reach function s2(). And if I'll click on Foo in extends part, it will open file f1.php.

I understand that IDE cant deside that file to use in that case... But giving the first of it - isn't good solution.
For example, NetBeans suggest user to choose that file to open.. Furthermore, NetBeans already khow that I'm using function s2() from file f2.php

It will be great if PHPed can handle this. Razz
Or this is configurable ???
View user's profileFind all posts by nezdalidaSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
I understand your problem and it is great the NetBeans asks you which file, but without using namespaces, having two or more classes of the same name just doesn't sound like a good idea to me. I wouldn't accept that situation in any of my projects.

If both those classes tried to load at the same time, you should get a PHP run-time error. Could you rename one of the classes?

In the PhpED Code Completion settings you could try ticking Limit scope to includes but if both of those Foo classes are included then that won't work.

Alternatively, if PhpED is quite simply detecting the wrong include file for a class, you might be able to tell PhpED to use a specific copy of that class. Go into Project Properties, click Includes and see if there is an incorrectly resolved include statement in that list, then on the right side change the resolved file name to the one that contains the correct class.
View user's profileFind all posts by plugnplaySend private message


Joined: 23 Feb 2011
Posts: 2
Reply with quote
plugnplay wrote:
I understand your problem and it is great the NetBeans asks you which file, but without using namespaces, having two or more classes of the same name just doesn't sound like a good idea to me. I wouldn't accept that situation in any of my projects.


I'm dealing with the same situation, but it's somebody else's code I'm reading and frankly, there's no obvious better way to do it. The class that PHPEd is finding is placed inside an "if(!class_exists(...))" by a plugin, most likely as a compatibility fix; in fact that compatibility fix is not needed on my particular setup, but I'd rather not remove a compatibility fix just to please my IDE. This framework handles file includes dynamically, so PHPEd isn't going to tell the difference between an included file and a non-included file. Adding something to the phpdoc would be an acceptable solution, since I'm mainly interested in how the new code that I'm writing calls that class, but I think Netbeans has the best solution.

In my specific case, I handled the problem by renaming the class that was being incorrectly found, re-running the "find declaration" call, and finally naming it back. That at least allowed me to find the important class in the other guy's code. Perhaps that workaround will help you, nezdalida.
View user's profileFind all posts by BrilliandSend private message
2 classes with same name
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic