fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

[FEATURE] Make PHP more strongly typed #1827

Closed rickmacgillis closed 9 years ago

rickmacgillis commented 9 years ago

PHP is a loosely typed language, and that makes it more malleable, but can also lead to more bugs. Native PHP 5 allows for type hinting for objects, arrays, and the like, but it doesn't allow for native scalar type hinting. The beauty of the matter is that PHP doesn't paint out the possibility of creating your own ability to type hint anything.

6 years ago, someone on the PHP manual wrote what's now a highly rated post describing the logistics of custom type hinting. (See: http://php.net/manual/en/language.oop5.typehinting.php#83442) I think that a lot of developers would benefit from the option of more strongly typing their code through custom type hinting for scalar types.

emlynwest commented 9 years ago

I think you have the wrong repo. This FuelPHP, a MVC framework written in PHP. You want PHP over at https://github.com/php.

I doubt that PHP well ever be a strongly typed language but if you want that then I'd recommend taking a look at Hack. http://hacklang.org/

rickmacgillis commented 9 years ago

I have the right repo. I want FuelPHP to integrate scalar type hinting into the framework, hence why I said it's "custom."

emlynwest commented 9 years ago

I am not sure what you mean. To modify the base language you'd have to either have a fork of PHP or an extension just to use Fuel.

What you linked there means that code written for Fuel would have to stay in Fuel, which is something I do not agree on for the most part.

rickmacgillis commented 9 years ago

I'm not talking about modifying PHP at all, though I'd be quite happy if scalar type hinting was native, so I'll also address that with them. Even if they did make it native, it would take a while before they released the code into the next release, and the world caught up (updated) to that release.

Anyway, as for having the code written for fuel, yes it would have to stay that way, just as it would need to stay that when when throwing an HttpNotFoundException, or when making calls to \Arr, \Input, and the like. If you program code with a framework, your not expecting to have to tear out the framework at some point, it's a framework, the base for your code. So, having the option to run scalar type hinting through an error handler would work just fine in that scope.

emlynwest commented 9 years ago

Regardless I do not feel that this should be included in an MVC framework. If it's something you wish to use in your applications then it should be easy enough to integrate into your application.

rickmacgillis commented 9 years ago

Fair enough. I can't say that I agree, but it's not my call. Thanks.