News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Type Hinting in PHP
March 05, 2012 @ 13:19:24

On PHPMaster.com today there's a new tutorial posted about using type hinting in your PHP applications to restrict the values passed into your methods.

Since PHP 5 you can use type hinting to specify the expected data type of an argument in a function declaration. When you call the function, PHP will check whether or not the arguments are of the specified type. If not, the run-time will raise an error and execution will be halted.

Included in the post are code examples showing how to define custom types in a function definition and what happens if you pass the wrong type in. Also mentioned is one of the main limitations to hinting - the fact that it can't be used on default PHP variable types.

0 comments voice your opinion now!
type hint example method default


blog comments powered by Disqus

Similar Posts

Matthew Weier O'Phinney: ZF2's New Controller::init()

Pierre-Alain Joye's Blog: Howto use a single php.ini for cli/cgi with htscanner, use 0.7.0 or later

Stuart Herbert's Blog: Quick Tip: Get, Set and Query in One Method

Sebastian Bergmann's Blog: Extended Reflection API for PHP 5

Derick Rethans' Blog: Overloaded properties (__get)


Community Events

Don't see your event here?
Let us know!


example laravel version security voicesoftheelephpant opinion community extension release laravel5 framework library language php7 api podcast series list introduction interview

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework