What does a \ (backslash) do in PHP (5.3+)?

后端 未结 4 1491
长情又很酷
长情又很酷 2020-11-22 16:22

What does a \\ do in PHP?

For example, CSRF4PHP has \\FALSE, \\session_id, and \\Exception:

publi         


        
4条回答
  •  攒了一身酷
    2020-11-22 17:02

    Namespaces

    In PHP 5.3+ the backslash \ symbol is used in namespaces. It is the start symbol to indicate a namespace and also serves as a separator between sub-namespace names.

    See official documentation about namespacing.

    Opcache

    Additionally in PHP 7.0+ some functions are replaced with opcodes by OPCache, which makes these specific functions run a lot faster. However this only works when the functions are placed in the root namespace. See this discussion about this topic. So besides namespacing, the \ indirectly also affects code optimisation.

    The following native functions benefit from this effect:

    "array_slice"
    "assert"
    "boolval"
    "call_user_func"
    "call_user_func_array"
    "chr"
    "count"
    "defined"
    "doubleval"
    "floatval"
    "func_get_args"
    "func_num_args"
    "get_called_class"
    "get_class"
    "gettype"
    "in_array"
    "intval"
    "is_array"
    "is_bool"
    "is_double"
    "is_float"
    "is_int"
    "is_integer"
    "is_long"
    "is_null"
    "is_object"
    "is_real"
    "is_resource"
    "is_string"
    "ord"
    "strlen"
    "strval"
    

提交回复
热议问题