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.


<?php 

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 and this is my Blog. I currently work at Nstein as a Senior Solution Architect & Business Analyst. Nstein Technologies develops and markets multilingual solutions that power digital publishing for the most prestigious newspapers, magazines, and content-driven organizations.

I am particularly interested in 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.

  • r0b: Thanks for sharing that great script! Saved me hundreds lines of includes in my project! [...]
  • anis: Excellent Slide bashar! j'ai rate la presentation [...]
  • Apprendre a utiliser Git | Anis Berejeb: [...] chez github. essayons de « checkouter»  un projet. Je choisis le projet [...]
  • Sheila: BAF rocks! [...]
  • anis berejeb: I think that there is no ambiguity because what is passed in the : $res = changeObj($obj = new StdC [...]