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

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

messy...its heading towards static typed like java, although that was the big difference between java and php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.