开发者

using datatype in php is possible?

开发者 https://www.devze.com 2022-12-29 06:02 出处:网络
i have seen this in php (symfony): public function executeShow(sfWebRequest $request) { // logic } i didnt know that you could declare a data开发者_如何转开发type in php?

i have seen this in php (symfony):

  public function executeShow(sfWebRequest $request)
  {
    // logic
  }

i didnt know that you could declare a data开发者_如何转开发type in php?

have i missed something?

could someone explain this.

thanks


This is a TypeHint:

PHP 5 introduces Type Hinting. Functions are now able to force parameters to be objects (by specifying the name of the class in the function prototype) or arrays (since PHP 5.1). However, if NULL is used as the default parameter value, it will be allowed as an argument for any later call. […] Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn't supported.

Note that the manual is somewhat vague here. TypeHints can enforce Arrays, Classes and Interfaces, but not scalars (integer, float, string or boolean). We might get scalar typehinting in PHP 5.4/6 though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号