3 ms·
PHP has object checking. This is why I started using value objects in PHP. The VO's I use trow exceptions when you construct them with some bad value. This is
by pasta 9y ago
PHP has object checking. This is why I started using value objects in PHP.
The VO's I use trow exceptions when you construct them with some bad value.
This is great because when you use for example a natural positive integer object you are sure it is one.
So now I have 'type checking' and more secure code in PHP.
- patricklouys 9y agoPHP also supports other type declarations. But using lots of value objects is a good idea anyway. http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration http://php.net/manual/en/functions.arguments.php#functions.a...
- stiGGG 9y agoSince when does PHP has value types? Aren't all the classes reference types or you mean that Array thingie? And it is still the case with type declarations, that they make your code actually slower, because the runtime adds asserts in your code which gets evaluated at runtime?
- zaphar 9y agoRuntime type checking while useful does not offer the same level of safety as compiler time. It will catch sinner classes of errors but you'll still have bugs lurking in production.