tags:

views:

32

answers:

1

i have seen this in php (symfony):

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

i didnt know that you could declare a datatype in php?

have i missed something?

could someone explain this.

thanks

+4  A: 

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.

Gordon
More info in the docs: http://de.php.net/manual/en/language.oop5.typehinting.php
Max
@Gordon, you already included the link, sry. ;)
Max
messy...its heading towards static typed like java, although that was the big difference between java and php.
never_had_a_name