News Feed
Sections




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

PHPEasy.co.uk:
Tutorial Type Hinting in PHP
August 01, 2012 @ 12:14:35

On the PHPEasy.co.uk site there's a quick new tutorial posted about type hinting in PHP - how to use it and why you should use it in your code.

Type hinting allows you to tell a function which data type to accept for its arguments. When you call a function, if a type hint is present, the argument passed will be checked to make sure it is of the type specified. If a function has control over what it accepts as an argument, then it is more likely that the code within the function will have the data it needs to perform the task it is intended for.

He includes two code examples - one not using a type hinting on the parameters (assuming the correct arguments) and another forcing the input of the "PrintGuitar" method to be a "Guitar" object instance. You can find out more about type hinting in the PHP manual.

0 comments voice your opinion now!
tutorial typehint example code beginner


blog comments powered by Disqus

Similar Posts

Elizabeth Smith's Blog: Treeviews and Cell Renderer Properties - Practical PHP-GTK

PHPMaster.com: Openbiz Cubi: A Robust PHP Application Framework, Part 2

Steven Macintyre's Blog: Building a Modular Zend Framework CMS

SitePoint PHP Blog: Automate PHP with Phake Real World Examples

HowTo Forge: Installing Lighttpd With PHP5 And MySQL Support On Fedora 7


Community Events





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


language interview configure podcast series introduction laravel wordpress release testing install threedevsandamaybe framework code opinion developer community refactor list unittest

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