![]() |
Type Hinting in PHP 6
So, as far as i understand, php 5.whatever we're currently on supports type hinting in classes when you're dealing either with arrays or objects. But, it doesn't allow us to declare variable types of methods which accept strings, ints, booleans, and these basic types.
I read somewhere that there is a debate over whether or not they should include this in php 6. What do you all think? Personally, I think it would be nice to have the option of writing classes this way just because I think it makes the code more self documenting and easier to deal with for future developers or my future self who might have no idea what i was doing when i wrote something. I don't know what the downside would be. Thoughts? |
I think a part of PHP's beauty is that it does not have strong typing, or a distinction between types of objects and primitives.
Doing Java development shows the contrast between the two ideologies. In one, you can document things easily and do many things quickly and dynamically. In the other, you have the assurance that what you specify is what is (usually). Type Hinting is enough for most purposes, and simple naming convention with mixed type checking should be enough for primitives. |
I agree that its very nice not to be forced to declare variable types in PHP, and this feature is definitely an asset.
That being said, I think the option to declare them in class methods would be beneficial, so that I don't have to manually check its type later. I think its cleaner too, than naming variables like $intMyVar. I do agree though that PHP's flexibility with variables is a beautiful thing about it :-) |
I'm a C programmer, so naturally I am for fairly tight type hinting. I find it one of PHPs major flaws, I like being able to know what type the variable is.
|
VI, it's called a feature, not a flaw. ;-)
|
| All times are GMT. The time now is 12:21 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0