PHP - Force function parameter to integer

前端 未结 2 1807
情话喂你
情话喂你 2020-12-12 05:04

In PHP you can do the following thing:

class Something {// bla bla}

function functionName(Something $object) {
    // Do stuff here  ^^^^^^^^^
}
         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 05:14

    You can't typehint scalar types in PHP. The only chance is to use a wrapper type. The SPL library ships with SplInt for that purpose.

    Update: Looks like PHP 7 offers that feature. Sigh, times changed :)

提交回复
热议问题