FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Why type hint when you can type cast
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Why type hint when you can type cast [message #182361] Wed, 31 July 2013 07:12 Go to next message
Bruce Lee is currently offline  Bruce Lee
Messages: 2
Registered: July 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Hi

Apart from the fatal error generated by type hinting when not passed values as array or object as described on the php manual, is there any thing else that will make me use type hinting over type casting?


Thanks
Re: Why type hint when you can type cast [message #182364 is a reply to message #182361] Wed, 31 July 2013 08:38 Go to previous message
Richard Damon is currently offline  Richard Damon
Messages: 58
Registered: August 2011
Karma: 0
Member
add to buddy list
ignore all messages by this user
On 7/31/13 7:12 AM, Bruce Lee wrote:
> Hi
>
> Apart from the fatal error generated by type hinting when not passed
> values as array or object as described on the php manual, is there
> any thing else that will make me use type hinting over type casting?
>
>
> Thanks
>

The major purpose of type hinting IS to get the fatal error to detect
that you passed the wrong type to the function. If your interface says
you need to pass a foo, you want to make sure you pass a foo. The type
hint says you don't need (as much) to validate that the correct type was
passed (and you rarely have a good recovery path if the wrong type was
sent).

If you don't need to require a given type to be sent to you, but have
reasonable recovery paths for other types, don't use a type hint to
require it.
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Education Path to become a PHP developer using free online courses
Next Topic: Reading a file on same server
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Oct 18 18:18:46 EDT 2017

Total time taken to generate the page: 0.00637 seconds