开发者

using datatype in php is possible?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜