Home>
Assumptions

This application uses Laravel.
First, modify composer.json as shown below to add a helper function.

"autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App \\": "app /"
        },
        "files": [
            "app/helpers.php"
        ]
    },
Applicable source code

Depending on the editor, a backslash is added at the beginning as shown below when calling a helper function.
By the way, it works even if there is no backslash.

\ helper_function ()


I would like to know when this backslash is necessary and useful.

  • Answer # 1

    I think it will be the use of global classes and functions in the namespace.

      

    How do I use inner or global classes in a namespace?
      Namespace notes: PHP
      When specifying a global space class or function in the name space, a backslash (\) can be added before the class name.