Declaring Variable Types in PHP?

后端 未结 5 620
灰色年华
灰色年华 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:17

    1. Specifying a data type for a function parameter will cause PHP to throw a catchable fatal error if you pass a value which is not of that type. Please note though, you can only specify types for classes, and not primitives such as strings or integers.
    2. Most IDE's can infer a data type from a PHPDoc style comment if one is provided. e.g.
    
    /**
     * @var string
     */
    public $variable = "Blah";
    

提交回复
热议问题