by gjsman-1000 · 4y ago · 0 comments
I would ask though that if any PHP developers are reading this, I would love a feature called `modern_syntax` or similar which represents a major break in backwards compatibility in exchange for modern language conventions (i.e. no `$` prefix on variables, no `;` ending lines, perhaps some renamed core functions for consistency - we can have a debate about this). Kind of like how we have `strict_types`. Or, perhaps it could be invokable on a per-file basis, by using `<?phpmodern` instead of `<?php`. Then you could have your traditional PHP framework (say, Laravel) which has years of work on it remain intact while having a modern-PHP layer of your app-specific code on top.
That would help, I would argue, with killing many of the PHP-specific criticisms while allowing some degree of backwards-compatibility.
I don't see why appeasing critics should be the goal of PHP.
Removing $ and ; signs doesn't help me at all. I actually like the "$" sign. Maybe little bit less ;, but I don't really notice it.
But I would certainly notice the mess of splitting language syntax into two separate branches.
Breaking changes in language are not fun to address and take away the time from building features.
I would be a lot more happy with generics. Or scalar objects, something like:
$string = "abc";
var_dump($string->length()); // int(3)
var_dump($string->startsWith("a")); // bool(true)
https://github.com/nikic/scalar_objects
That would make PHP standard library a lot easier and fun to use.
It's mostly legacy stuff like built in function naming.
I just don't get why people tend to type the semicolons in JS/TS when they don't need to like they don't know it's optional.
```
>>> (bool)"1";
=> true
>>> (bool)"0";
=> false
>>> (bool)"false"
=> true
```(there are plenty of other things like that; the default call-by-value is also unexpected)
Also: Laravel has plenty of "magic" ie things are intercepted via runtime reflection and then rerouted into something that hopefully "does-the-right-thing". It obfuscates control flow, causes unexpected side-effects and confuses IDEs and developers alike.
Even the popular frameworks have combinations of subawesome code and silly ideas. Just the latest example I ran into:
```
int append(string $path, string $data) /* the signature of the Filesystem facade */
/* the implementation in FilesystemAdapter: */
public function append($path, $data, $separator = PHP_EOL)
{
if ($this->fileExists($path)) {
return $this->put($path, $this->get($path).$separator.$data);
}
return $this->put($path, $data);
}
```
- It's not correct as it will add (ffs why?) a newline in between the files.
- Performance wise, this is bloody awful.
- however, you *can* specify the separator in any call as the facade interface is just documentation and is bypassed via reflection (but that confuses your IDE)There were even some incorrect type casting specially with numbers and "numeric strings", which were fixed recently.
I use strict typing in every new piece of code I work on, which largely fixed the problem.
Laravel, while being extremely popular, isn't exactly the flagship choice for "quality code", not even Laravel claims it to be. Symfony framework gets a lot of things right, and IMO the showcase for more modern PHP.
Not needing to `\` every other line is also nice.
And then there's javascript, of course, eating glue in the corner as usual.
And more relevant, this has the effect of suppressing the expression's value when used in tail position of a block, by moving from the second to the first branch of the block expression grammar: https://doc.rust-lang.org/reference/expressions/block-expr.h...
Which also explains why it sometimes doesn't work e.g. in non-block match arms, because they're not blocks, and thus don't accept statements.
Python is nice, but the whitespace can often have issues, and formatters can be wonky in vscode... It's pretty though, like rails. Still, I'm most comfortable w/ Laravel/php so will stick w/ that for time-being.
For example, as near as I can tell I still can't have fopen() tell me why it failed; it just returns False and one of those magic E_WARNING things. This is simple stuff, but also pretty critical to correctly implement some basic file I/O of the kind that you can do in ... pretty much any other language.
Language blitz is nice, I guess, but not really "needed" as such. PHP5-the-language never really prevented me from doing things, PHP5-the-standard-library did, and from the looks of it, it still does. Things like no $ or ; are non-issues, and a good example of the wrong focus on syntax and "blitz" rather than things that actually matter.
I'm not expecting things to be free of inconsistencies, oddities, historical baggage, etc. I just want ... basic functionality.
2. it introduces errors which can remain latent or unfound for a while, especially when you're just changing the parameter ordering of a function in a dynamically typed language
PHP has actually been awesome at preserving backwards compatibility.
I wrote a server, when PHP 4 was still the cutting edge, and it still works, now, at 8.1 (although I know that it is being rewritten, in order to leverage things like Laravel).
I got a call at end of 2017 saying "this isn't working". Someone else had taken over hosting and been upgrading PHP along the way. There was finally something that broke (some weird dynamic object stuff that was making up for some PHP4 shortfall at the time) and... I did some small patch to get around it but suggested they have someone rebuild, either in PHP 7 or ... any tech from 2017. Just needed to migrate relatively simple database over.
I pointed out that they had basically 13 years of hassle-free system - that's generally a bit outside the norm for that sort of thing, and... that was the recommendation they gave back to their org's board of directors (small non-profit sort of thing).
Whereas... imagine if Python 3 rolled out simply as an optional "mode of operation" on top of Python 2. If you opt-in on this particular file, the syntax requirements are different. Obviously that would prevent some deeper changes, but it would help modernize the language without as much of a radical break.
It's easy to imagine: Python 3 would not have existed. At all.
Python 3 changed fundamental language semantics in ways which went way beyond syntax, that's why the core team shoveled so many changes in: they were breaking the language in a way which didn't brook mere syntactic opt-ins, this meant additional changes were minor issues easily handled compared to the fundamental difficulty of overhauling the language's entire string model and significant parts of the object model.
> If you opt-in on this particular file, the syntax requirements are different.
You're about 20 years late to the party, welcome to Python 2.1: https://docs.python.org/3/whatsnew/2.1.html#pep-236-future-d...
Think about something like WordPress, it powers so much of the internet, they're not going to be doing massive rewrites so that PHP can fix some legacy issues.
See python2 vs python3. It almost ended the language IMHO.