Home » Php » regex – Notepad++ function list PHP not working if I didn't close the PHP tag

regex – Notepad++ function list PHP not working if I didn't close the PHP tag

Posted by: admin July 12, 2020 Leave a comment

Questions:

I want to use function list feature from notepad++ for my PHP code
Actually the function list is working normally if I write the close PHP tag ( ?> ).. But if I didn’t close the PHP tag, the function list is not working

I just want, the function list is still working even I didn’t close the PHP tag

See the image
On the top is without close PHP tag
On the bottom is with close PHP tag

enter image description here

Then I read this, notepad++ function list doc
https://notepad-plus-plus.org/features/function-list.html

I guess, I need to edit the regex.. But the problem is I can’t edit the regex because the regex looks like too complex for me

This is the regex and xml of PHP function list

<parser id="php_function" displayName="PHP" commentExpr="((/\*.*?\*)/|(//.*?$))">
<classRange
    mainExpr="^[\s]*(class|abstract[\s]+class|final[\s]+class)[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*([\s]*|[\s]*(extends|implements|(extends[\s]+(\|[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+[\s]+implements))[\s]+(\,[\s]*|(\|[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))+[\s]*)?\{"
    openSymbole = "\{"
    closeSymbole = "\}"
    displayMode="node">
    <className>
        <nameExpr expr="(class|abstract[\s]+class|final[\s]+class)[\s]+[\w]+"/>
        <nameExpr expr="[\s]+[\w]+\Z"/>
        <nameExpr expr="[\w]+\Z"/>
    </className>
    <function
        mainExpr="^[\s]*((static|public|protected|private|final)*(\s+(static|public|protected|private|final))+[\s]+)?(function[\s]+)+([\w]+([\s]+[\w]+)?([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+))?([\w_]+[\s]*::)?(?!(if|while|for|switch))[\w_~]+[\s]*\([^\{]*\{">
        <functionName>
            <funcNameExpr expr="(?!(if|while|for|switch))[\w_]+[\s]*\([^\{]*"/>
            <!-- comment below node if want display method with parmas -->
            <funcNameExpr expr="(?!(if|while|for|switch))[\w_]+"/>
        </functionName>
    </function>
</classRange>
<function
    mainExpr="^[\s]*function[\s]+\w+\("

    displayMode="$className->$functionName">
    <functionName>
        <nameExpr expr="(?!(if|while|for))[\w_]+[\s]*\("/>
        <nameExpr expr="(?!(if|while|for))[\w_]+"/>
    </functionName>
    <className>
        <nameExpr expr="[\w_]+(?=[\s]*::)"/>
    </className>
</function>
</parser>

Can someone help me

Thank you

How to&Answers:
[Solved]

We just need to add enter/add new line after close the class or function tag

So maybe this is a bug

Thanks

Answer:

For me the problem was that there was no closing PHP tag.

May be that helps someone.

Add a “?>” closing PHP tag if it is already not there.

Answer:

There are several reasons why function list can’t render function tree.

  1. In older versions of Notepad++ PHP section closing tab is required. Just simple add ?> at the end of file. Sometimes after closing tab new line is required.
  2. functionList.xml incorrect parse PHP file. For example this function description broke function list rendering:
    /**
     * Unset an instance of this class.
     *
     * @param Spreadsheet $spreadsheet Injected spreadsheet identifying the instance to unset
     */
    public function __destruct()
    {
        $this->workbook = null;
    }

In this case you must change (or add) commentExpr In functionList.xml in %APPDATA%
(There are two functionList.xml locations. Program Files directory and %APPDATA% directory)

<parser
    id         ="php_syntax"
    displayName="PHP"
    commentExpr="(?'MLC'(?s-m)/\*.*?\*/)|(?'SLC'(?m-s)(?:#|/{2}).*$)|(?'STRLIT'(?s-m)&quot;[^&quot;\]*(?:\.[^&quot;\]*)*&quot;|&apos;[^&apos;\]*(?:\.[^&apos;\]*)*&apos;)"
>

Answer:

The internal “function list” does not work at all for me. I tried to delete one or both “functionlist.xml” files, which was recommended at some sites, but nothing worked for me.

I prefer the plugin “functionList” from
https://sourceforge.net/projects/npp-plugins/files/Function%20List/

with the Patch from
https://github.com/gwarnants/FunctionList-PHP-Patch

which works great with my Notepad++ 6.9.2

Answer:

Replace in functionList.xml, the php parser. Use this new one you can find in the notepad++ forums ->

https://notepad-plus-plus.org/community/topic/15124/php-function-list-and-abstract-functions/17

it can handle abstract class and functions.