Declaring Variable Types in PHP?

后端 未结 5 618
灰色年华
灰色年华 2021-02-03 17:19

I was trying to get my Netbeans to autocomplete with PHP, and I learned that this code is valid in PHP:

function blah(Bur $bur) {}

A couple of

5条回答
  •  心在旅途
    2021-02-03 18:07

    #2 : (...) How can I declare the type of a variable in PHP if I'm not in a function?

    I recently heard about "settype()" and "gettype()" in PHP4 & 5
    You can force the variable type anytime easily


    From PHP.net :

    bool settype ( mixed &$var , string $type )

    Parameters

    var : The variable being converted. type : Possibles values of type are:

    • "boolean" (or, since PHP 4.2.0, "bool")
    • "integer" (or, since PHP 4.2.0, "int")
    • "float" (only possible since PHP 4.2.0, for older versions use the deprecated variant "double")
    • "string"
    • "array"
    • "object"
    • "null" (since PHP 4.2.0)

    [ :D First visit, first comment...]

提交回复
热议问题