Declaring Variable Types in PHP?

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

    It's called type hinting, added with PHP 5. It isn't quite what you may be expecting if you are coming from a language like Java. It does cause an error to be thrown if you don't pass in the expected type. You can't type-hint primitives, though (no int $bur).

提交回复
热议问题