Tapatalk

PHP function list with classes, member functions and global functions

PHP function list with classes, member functions and global functions

13
Basic UserBasic User
13

    Jun 05, 2017#1

    Hello everyone,
    I am trying to use UES for my PHP projects.
    I would like to see in the "Functions List" tab not only the functions of the current file but also the classes, the members...
    I noticed that all of the classes of my project have been parsed and appear in a long list which is the "Tags" tab. So long that it is completely useless.
    Does anyone know how I can have all of my classes be displayed in the "functions list"?
    Thanks so much.

    6,685587
    Grand MasterGrand Master
    6,685587

      Jun 05, 2017#2

      Jerome, I'm using UEStudio for C/C++ and not for PHP coding. So I'm perhaps not the right user to help you.

      But open Advanced - Settings/Configuration - IDE - IntelliTips - Function tips which has the setting Use function tips data (if available) for function list. With this setting checked the function list displays the symbols as found by internal parser of UEStudio. If this setting is not checked, the function list displays the data as found by the regular expressions in syntax highlighting wordfile php.uew. So first I suggest to uncheck this setting if currently checked and look on function list after having refreshed it with pressing key F8.

      Next right click into the function list to open its context menu and see the function list related commands and options. There is also the command Refresh function list. Configuration opens the dialog for customizing the regular expressions used to find whatever you want to see in the function list from your PHP files.

      We can help you to customize those regular expressions to get finally the display you would like. But please post an example PHP code block and what should be displayed from this block in which style (flat or tree) and in which order in function list. Somebody of us like me can help on customizing the Perl regular expressions used to find the data of interest for the function list although not having PHP files at all when questioner clearly describes what is wanted.
      Best regards from an UC/UE/UES for Windows user from Austria

      13
      Basic UserBasic User
      13

        Jun 05, 2017#3

        Thanks your reply Mofi!
        You definitely pointed something: I unchecked the "Use function tips data" checkbox and got some update in the functions list.

        I went to the php.uew file but no regular expressions exist for classes. I also went to c_cplusplus.uew, it is also lacking such info I could have copied.

        I added a simple regular expression to test:
        /TGBegin "Class"
        /TGFindStr = "^[ \t]*class[ \t]+([a-zA-Z0-9_]+)"
        It worked but it is not really what I want.

        I appreciate your help very much and as suggested, I am posting two views of the same code snippet, one with UES (and my 'class' regexp), and one with CodeWright (which I am trying to replace...). The Functions list outlined in CodeWright would be OK for me.

        (c) c_markets
        (f) ui_display_form
        (f) get_list_countries
        ...

        Under UES it is even not sorted properly: as you can see classes are listed first, then functions.
        If you have an idea, it is more than welcome.

        PS: I am surprised that this does not come out of the box. That would help people make their decision : I have been evaluating UE/UES for years but never bought it nor used it yet.
        Thanks again!

        Jerome
        codewright-php-regexp.PNG (21.57KiB)
        In CodeWright: not perfect but good for me
        ues-php-regexp for classes.jpg (83.69KiB)
        UES

        6,685587
        Grand MasterGrand Master
        6,685587

          Jun 06, 2017#4

          I don't have any PHP file for testing modifications on the regular expressions in wordfile, best done via Configuration to avoid syntax mistakes. Please would you compress an example PHP file into a ZIP or RAR archive and attach this archive to your next post.

          According to PHP Manual - Basics - class the Perl regular expression to use to find valid class names would be:

          ^[\t ]*class[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)

          The first character can't be a digit. I removed A-Z as the search expressions in the wordfile are used always in case-insensitive searches and therefore a-z in a character class is enough to match lower case and upper case characters.

          Nesting the functions, function parameters and function variables within classes is perhaps what you want, i.e. php.uew contains:

          Code: Select all

          /TGBegin "Requires"
          /TGFindStr = "^[\t ]*require(?:_once)*[\t "']+([0-9a-z$&*\-./:=?\\^_]+)["']*;"
          /TGEnd
          /TGBegin "Includes"
          /TGFindStr = "^[\t ]*include(?:_once)*[\t "']+([0-9a-z$&*\-./:=?\\^_]+)["']*;"
          /TGEnd
          /TGBegin "Classes"
          /TGFindStr = "^[\t ]*class[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
          /TGBegin "Functions"
          /TGFindStr = "^[\t ]*(?:(?:abstract|final|private|protected|public|static)[\t ]+)*function[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
          /TGFindBStart = "\{"
          /TGFindBEnd = "\}"
          /TGBegin "Parameters"
          /TGFindStr = "[\t ]*(\$[a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*[\t ]*=[\t ]*(?:array[\t ]*\((?:[^()]*|(?:[\t ]*array[\t ]*\(.*?\))+[\t ]*)\)|".*?"(?<!\\")|'.*?'(?<!\\'))|[^,]+)"
          /TGFindBStart = "\("
          /TGFindBEnd = "\)\s*(?:\{|#|//|/\*)"
          /TGEnd
          /TGBegin "Variables"
          /TGFindStr = "^[\t ]*\$([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)[\t ]*="
          /TGFindBStart = "\{"
          /TGFindBEnd = "\}"
          /TGEnd
          /TGEnd
          /TGEnd
          
          Please make sure that in context menu of function list option Flat list is not enabled to get the list displayed as tree. The usage of option Sort is up to you.
          Best regards from an UC/UE/UES for Windows user from Austria

          13
          Basic UserBasic User
          13

            Jun 06, 2017#5

            Thanks, this looks good!
            I am attaching a sample file so that you can test and get the catch:
            This file contains several classes and one function called quote_upper().

            The catch is that I don't see how to capture this function below the classes...
            If you put a regexp to catch functions out of the class block, classes methods will be captured twice.

            CodeWright solves this by just capturing a class or a function and displaying in the order it encounters each element on parsing.
            This is why sorting in natural order (as it is encountered in the file) is important, but unless mistaken it does not seem to be an option with UES grouping mechanism.

            Thanks again for your time.
            $-rail.zip (1.83 KiB)   59

            6,685587
            Grand MasterGrand Master
            6,685587

              Jun 07, 2017#6

              Thanks for the example file.

              Functions outside a class are indeed a problem for a tree view list of all classes and functions. For that reason I concentrated first on getting a function list as CodeWright displays.

              With option Sort unchecked in context menu of the function list those regular expressions below show the same list.

              Code: Select all

              /TGBegin "Requires"
              /TGFindStr = "^[\t ]*require(?:_once)*[\t "']+([0-9a-z$&*\-./:=?\\^_]+)["']*;"
              /TGEnd
              /TGBegin "Includes"
              /TGFindStr = "^[\t ]*include(?:_once)*[\t "']+([0-9a-z$&*\-./:=?\\^_]+)["']*;"
              /TGEnd
              /TGBegin "Classes & Functions"
              /TGFindStr = "^[\t ]*(?:(?:abstract|final|private|protected|public|static)[\t ]+)*(?:class|function)[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
              /TGEnd
              
              It looks like all your classes start with c_ and therefore no additional indicator would be necessary. But that would be possible with modifying the regular expressions for classes and functions to:

              Code: Select all

              /TGFindStr = "^[\t ]*(?:(?:abstract|final|private|protected|public|static)[\t ]+)*([cf])(?:lass|unction)[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
              
              Of course that expression would interpret also flass and cunction as keyword for a class or function definition, but I suppose that this does not matter in real world as those two strings are not found in any PHP file with a positive match.

              The parameters of a function and the local variables of a function are not listed anymore in function list with these two variants of regular expression sets because an additional condition like "search for parameters and variables only if a function definition is found" is not possible with a regular expression.

              But the parameters of a function could be displayed in same line as the function name in function list by using the following regular expression for classes and functions:

              Code: Select all

              /TGFindStr = "^[\t ]*(?:(?:abstract|final|private|protected|public|static)[\t ]+)*(?:class|function)[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)(?:[\t ]*(\([^)]*\)))?"
              
              But getting the functions with their parameters listed is perhaps not needed as on referencing a function UEStudio automatically shows the parameters while typing except this IntelliTip feature is disabled in configuration. So the function list could be also without parameters to make them easier to find and read in function list.

              I have never understood why local variables of a function should be displayed in function list. I don't have them in my function lists. The symbol database contains the local variables and therefore I can easily jump to definition of a local variable using Find Symbol command executed by key and auto-completion also offers the variables in the displayed list. So I do not really understand why having local variables in function list. Too much information displayed in function list is counterproductive in my estimation. It takes more time to find all the data to display in function list and it takes more time for the user's brain to find something in function list with too much data displayed.

              Please let me know if you are happy with one of the provided solutions or if you would prefer a different function list.
              Best regards from an UC/UE/UES for Windows user from Austria

              13
              Basic UserBasic User
              13

                Jun 07, 2017#7

                Hello Mofi and thanks very much for these settings. it is very helpful as it allows me to learn with a real example for which I am concerned!
                I totally agree with you : functions list should remain simple; for me it is just a kind of map that allows me to go quickly to a specific part of my file with a single click.
                I have completely remove Parameters and Variables.

                I will play with your code to fine tune my configuration: I must say that having classes and members in a hierarchical tree is something nice; I guess I need to try them in turn.

                Again thanks very much for your nice help.
                Jerome

                  Jun 16, 2017#8

                  Hi again,
                  In fact I was able to refactor a little bit Mofi's php.uew file in order to separate functions from class members.
                  Here it is, I only assumed that a class member would always have a keyword (public|static|...), whereas a function does not need it.

                  Code: Select all

                  /L8"PHP" PHP_LANG Nocase EnableMLS Line Comment = // Line Comment Alt = # Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = "' File Extensions = PHP3 PHP4 PHP5
                  /LanguageMarker = "php"
                  /TGBegin "Requires"
                  /TGFindStr = "^[\t ]*require(?:_once)*[\t "']+([0-9a-z$&*\-./:=?\\^_]+)["']*;"
                  /TGEnd
                  /TGBegin "Includes"
                  /TGFindStr = "^[\t ]*include(?:_once)*[\t "']+([0-9a-z$&*\-./:=?\\^_]+)["']*;"
                  /TGEnd
                  /TGBegin "Class"
                  /TGFindStr = "^[\t ]*class[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
                  /TGBegin "Members"
                  /TGFindStr = "^[\t ]*(?:(abstract|final|private|protected|public|static)[\t ]+)*function[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
                  /TGFindBStart = "\{"
                  /TGFindBEnd = "\}"
                  /TGEnd
                  /TGEnd
                  /TGBegin "Functions"
                  /TGFindStr = "^[\t ]*function[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"
                  /TGEnd
                  
                  I wonder if this is really true, but at least for me, it is a convention that I can adopt for my coding.
                  It might help some others around here.

                  Thanks again to Mofi for the relevant suggestions.
                  functions.png (3.12KiB)

                  6,685587
                  Grand MasterGrand Master
                  6,685587

                    Jun 16, 2017#9

                    Yes, I also like what the function list displays on using your set of Perl regular expressions in PHP wordfile and viewing the function list for your example PHP file. The function list displays a list of all classes and a list of all functions for easy navigating to either a class or a function. And if being interested in which member functions a class has, a click on [+] symbol of a class shows them. That's exactly what I expect from a function list for my work and if I would code PHP files, I would use your set of Perl regular expressions. Good job!
                    Best regards from an UC/UE/UES for Windows user from Austria

                    13
                    Basic UserBasic User
                    13

                      Jun 17, 2017#10

                      Thanks Mofi.
                      In fact there is something I still don't get about the regular expression and I could not find any documentation in the help file.
                      I don't understand what part is exactly captured and displayed.
                      In the above example, a class member is displayed with its "keyword" such as public.
                      The regular expression used is the following:

                      /TGFindStr = "^[\t ]*(?:(abstract|final|private|protected|public|static)[\t ]+)*function[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"

                      I would like to get rid of any of the abstract|final|... keyword.
                      I tried to remove some () in the expression but it never works.

                      May I ask you what should be done?
                      Thanks

                      6,685587
                      Grand MasterGrand Master
                      6,685587

                        Jun 18, 2017#11

                        That is easy, use:

                        /TGFindStr = "^[\t ]*(?:(?:abstract|final|private|protected|public|static)[\t ]+)*function[\t ]+([a-z_\x7f-\xff][0-9a-z_\x7f-\xff]*)"

                        (...) ... is a capturing group which can be referenced with \1, \2, \3, ... in search or replace string. For the function list all strings found by the expression inside each capturing group are concatenated with a single space between.

                        (?:...) ... is a non capturing group. Such groups are used to build an OR expression or to apply a multiplier like * to an entire expression.
                        Best regards from an UC/UE/UES for Windows user from Austria

                        13
                        Basic UserBasic User
                        13

                          Jun 19, 2017#12

                          Thanks Mofi!
                          This exactly the information I needed and that I could not find in the UES documentation. Did I miss it?
                          Have a nice day.

                          6,685587
                          Grand MasterGrand Master
                          6,685587

                            Jun 19, 2017#13

                            In help of UEStudio the Perl regular expression syntax is only briefly explained. The Perl regular expression engine is so powerful but also so complex in syntax that it fills entire books and websites and therefore can't be explained in total on a single help page. A very good website regarding Perl regular expression syntax is for example Regular Expressions. Embedded in UltraEdit is the Boost Perl regular expression library. Which version of Boost Perl regex library is embedded in which version of UE/UES in which extend is out of my knowledge.
                            Best regards from an UC/UE/UES for Windows user from Austria