Skip to content

Improper formatting of PHP function namespaces #2887

@danon

Description

@danon

Information:

  • Prism version: Newest

Description
While prism understands namespace declaration (namespace Hello), namespace definition (use Hello) and using classes with namespaces (new \Hello\Hi(); and \Hello\Hi::class), it doesn't understand function namespaces. In PHP, functions can be namespaced as well.

mb_string(); // call to a global function
\mb_string(); // namespace \ is global
\a\b\c\mb_string(); // function in \a\b\c namespace

In Prism.js, the namespace parts \a\b\c are makred as .token.plain, which I don't believe they are.

Technical tips:
Only calls to methods need this checks - so it must be \w+\\\w+\(\). Namespaces and functions cannot start with letter. There can't be a space between namespaces and functions as well as between namespaces and backslashes.

Example
https://prismjs.com/test.html#language=php&text=%3Cphp%0A%0Aecho%20%5Cmy%5Chello%5Cmy_function()%3B%0A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions