Structure window, PHP -- what's the logic behind default sorting of functions/methods


I'm wondering -- what is the logic behind default sorting (when sorting alphabetically and by visibility is turned off) of functions/methods/fields/variables in Structure window for PHP file.

In my observations the PHP entries are sorted somehow randomly (as well as for JavaScript file, but I'm not that much sure here, as I simply do not have big enough js-files). On another hand -- CSS file entries are sorted as they appear in the file (as far as I can tell -- I have not checked this precisely).

Here is the example (see attached file -- which is stubs for wincache extension): All functions are declared in alphabetical order, but in Structure window they are absolutely not (see screenshot attached). I saw no difference between builds -- same bahaviour in 1.0.2 as well as latest EAP build.

Is it a bug .. or that is supposed to be in this way?


I'm aware of File Structure Pop-up (where all the entries are sorted alphabetically) and Go-to Symbol pop-up (which covers whole project, or maybe even external libraries), but I'm relaying on Structure window as it provides a quick overview of your file and all my files are usually quite small so I can see whole file structure without scrolling up/down. And I'm also grouping similar by nature/task functions/methods together, so if sorted alphabetically they may appear in different parts of the Structure window but are next to each other in file (for example, such methods I would do next to each other: setCardNumber, getCardNumber, isValidCardNumber).


From the end user perspective there is no any default ordering of elements in the structure view. In other words it's essentially random. If you want to see functions/methods in a sorted order, you have to use "Sort by visibility" and/or "Sort alphabetically" buttons. That's all you have got. Using OOP you could potentially group functions by defining interfaces (not available in PHP at the moment) but in case of non-class functions this approach will not work and there should be some other way to do that. For now at least I would use special function name prefixes to make sure that the functions will show up together in the structure view when sorted alphabetically.


Hi Rustam,
Thanks for your reply.

Can you make the change to your code, so that by default (when no sorting is applied), instead of displaying entries in random order, they will be listed in order how they were defined in file ?

My thoughts are: You (the IDE) analysing the file in order to display it's structure, you're doing it from beginning of the file to the end. So why it displays entries in random order if it can easily be done (arguable point, but hey :) ) in "natural"/in-order-of-discovering order.

I just would like to know (before I go  and submit a feature request (or shall I do it at all)) if that makes any sense -- to have it implemented this way and how incredibly easy/difficult it will be.

BTW -- even if sorted alphabetically, and you copy-paste quite few functions (let's say 3-5), after pasting them back into the same file (maybe into diff place in file) the structure window will fail to sort them properly (aphabetically) straight away -- but will do nice if forcing to refresh it (by, for example, switching to another tab and back). But this is a minor thing.


@Andriy Bazanov

You are correct, we need to amend the sorting so its either A-Z or in order of appearance, with latter as a default.

Please file a request to issue tracker, and your P.S. as separate bug report.


Please sign in to leave a comment.