Would you like to see more type hinting in PHP ?

In: PHP| Programming language

20 Mar 2009

One of the characteristic of PHP is that it doesn’t do strong typing.

PHP 5.1 introduced Type Hinting. Functions were able to force parameters to be objects (by specifying the name of the class in the function prototype) or arrays.

I recently read one RFC (Request For Comments) - on PHP.net wiki - from Felipe Peruna about Return value and parameter type hint. Basically, the idea is to allow to specify what will be the type of the result of a function or method. Here is an example.


class test {
    public function (int) foo(){
        // ...

In that previous example, the method foo must return an integer, if that’s not the case, then the following error will be triggered : “Catchable fatal error: The returned value must be of the type integer”.

I personally think this could come handy in some cases.

  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

Comment Form

Who am I?

My name is Bashar Al-Fallouji, I work as a Enterprise Solutions Architect at Amazon Web Services (Sydney, Australia).

I am particularly interested in Cloud Computing, Web applications, Open Source Development, Software Engineering, Information Architecture, Unit Testing, XP/Agile development, etc.

On this blog, you will find mostly technical articles and thoughts around PHP, OOP, OOD, Unit Testing, etc. I am also sharing a few open source tools and scripts.

  • dipan: Hi Bashar It's really awesome that you wrote this code. IT'll save tones of time of all developer. [...]
  • Bashar: Glad that you liked it ! [...]
  • Angel S. Moreno: well, there goes wasting a couple of hours of development and a couple of days of testing. I owe you [...]
  • Bashar: Thats right, the setSaveFile create a files containing an associative array of classname => filen [...]
  • Loggy: Jim's clarification in particular was pretty useful although I did have to dig down into the tree to [...]