But after you get productive with PHP there is no feature that I think I am missing from other similar languages.
But after you get productive with PHP there is no feature that I think I am missing from other similar languages.
- expressive type system with generics, union types, literal types, basically TypeScript. I can say "this function returns a string" or "this function returns an array", but not "this function returns an array of strings".
- specialized collection/hashmap data structures with good support across third-party libraries. Having one array() structure acting as both a sequence and an associative array at the same time is awful.
- a templating solution similar to JSX. I am spoiled by TypeScript's ability to typecheck my HTML views along with other code.
About the array issue don't we have same situation with JS and TS where you don't have dictionaries or hashmaps in the standard library and you have to use array or object ?
I like JSX too, maybe some PHP template would be made to copy JSX , but not all ages need to be that interactive and not all PHP code is rendering HTML, my current project uses angular1 for the frontend (it was something already created so there was no debate what tool to be used where I could have voiced an opinion).
As a personal opinion I prefer react to angular because I don't like the angular magic compile stuff, I like that react components are JS functions and I can breakpoint into a render functions. I also done some side toy projects with TS, I like it and I hope it gets more popular so new projects would use it but I am worried that we could get a wave of front end languages and we will not have a standard great language but many non standard languages.
ES6 has Map and Array, which are perfectly sufficient and distinguishable from each other. PHP core only has array() which tries to do everything. You can use array() to build a collection or an associative array and you cannot force it to only behave as one of those. Even Zend's PHP certification contains questions about what happens if you try to push a value into an array that uses associative keys. This is a joke.
I prefer React over Angular as well, but interactivity was not on my list of goals. I want a template syntax that combines valid markup, escaping by default, and TSX-style typechecking. Basically, I want XHP [0]. There is no other template engine for PHP that validates "values passed into this template" against "values used in this template" like TSX can, and no engine that ensures you're generating valid XML/HTML markup. I certainly agree that this is far less important than powerful types, but hey, one can dream :)
Bue ES6 is new, I never seen APIs that use Map , I often had to use an Object as dictionary and had to Google how to properly do it not to get extra keys and values from the Object.prototype.
I am not trying to say that PHP is better then TS, but as far as type safety my PHP code with PHPDoc is better type checked then JS code with JSDoc (we are using ES5).
I don't have experience with PHP rendering, but I assume you only have to escape unsafe input, don't have to escape markuup, have you tried twig, is it not safe https://twig.symfony.com/doc/2.x/filters/escape.html ?
I admit I like rendering with react, but I admit that reading a twig template is much simpler then reading JSX code (but I am condemned to use angular :-( ).
It's based on PHP, but adds:
Expressive type system with generics:
https://docs.hhvm.com/hack/types/generic-types
Specialized collections: vec, dict, keyset
https://docs.hhvm.com/hack/types/arrays
Templating solution similar to JSX: XHP
[0]: https://github.com/doctrine/collections
[1]: https://github.com/schmittjoh/php-option
You have some syntax to opt into a later release (e.g. doing `<?php(version=8)` at the start of a script.
In a major release, you then get rid of a load of cruft.
imagine the exponential complexity as old behaviours need to be kept around for various levels of opting in.
You also want a single version, not a gigantic pile of things to opt in to.
The only fear I'd have is a lack of big entity committed to PHP. In the heydays there was Yahoo, facebook and other giant companies relying on PHP and guaranteeing that there would be enough man power to weather any type of changes. Now I wonder how many people are left to push through breaking changes and rewrite/modernize the libraries and the ecosystem.
I'm not sure that's the wrong decision, but it's not a great one, either. Too much complexity in the implementation can kill the project. Too much complexity in the language can kill a person's hope of learning it.