3 ms·
Well comparing Go and PHP is kind of difficult, because they are targeting completely different goals. After some years of development, both languages have evo
by sandreas 8y ago
Well comparing Go and PHP is kind of difficult, because they are targeting completely different goals.
After some years of development, both languages have evolved a lot and they both can be used for many other things, that they haven't been designed for.
PHP was a dynamically typed scripting language to build personal homepages (Personal Home Page Tools). Today it is an object oriented, type hinted language that supports functional and object oriented programming, many database management systems and has a package manager (composer). I really like PHP (see https://github.com/sandreas/m4b-tool https://github.com/sandreas/m4b-tool for a proof), but some concerns about PHP have always been (and still are):
- backwards compatibility reaching too far
- way too big standard library (see levenshtein function)
- the "callable" concept - call_user_func_array([$obj, "method"])
- mixing up too many concepts (OOP, Traits, Functional style)
- the type system (which is getting better with php 7)
- unpredictable statements - empty($x), comparisons (== vs ===) and the "mixed" type
- the "array" type being array and dictionary and...
- the $ used for variable declaration
- $this-> is still needed for calling object methods
- "." for concatenation and "\" for namespace separation
Another bad thing about PHP is, that on most web servers it is meant to be stateless, which means that you are in trouble using technologies like websockets.
Some of these things unfortunately mean that PHP often is much slower than it could be - and this is where "go" can be a successor. Performance. If you really need FAST web apps and performance is the goal, go can be a nice choice. But for getting things done in a not too complex web page, i would always choose php.
- ddtaylor 8y ago> - the "callable" concept - call_user_func_array(["object", "method"]) For at nearly 10 years now PHP has had support for lambdas, meaning for most uses `$foo()` can be used instead and with the inclusion of the spread operator it's seldom used.
- sandreas 8y agoWith the "callable" concept i meant, that many things are seen as callable: [$obj, "methodName"] => callable for $obj->methodName() "str_replace" => callable for function "str_replace" ["ClassName", "staticMethod"] => callable for ClassName::staticMethod() "ClassName::staticMethod" => callable for ClassName::staticMethod() function() {} => callable for a lambda I would prefer a "ClassMethod" and a "Function" type, instead of using strings. $x = phpinfo; $x(); $y = $obj->method; $y(); But i don't think, this is possible, because PHP supports global constants and function names cannot be distinguished from constants, especially because PHP is not case sensitive regarding functions and classnames. But I see, that my karma has decreased with this post, so it seems, that not many are in my opinion...
- waibelp 8y agoIt's possible to write bad code in every language.
- sandreas 8y agoSure it is... and nearly every language has concepts i like and concepts that i don't like... The above list is just an indeed subjective list of things i don't like about PHP, although i like PHP in general and it is NOT a PHP rant!