If you work long enough with a language and figure out most its quirks, it's a breeze. It's nice that they are adding all these new features, but they are hardly what makes it or break it for me.
Here is the one features that is taken for granted in "modern stacks":
Edit file -> Alt+tab ctrl+R. Oops, Alt+tab fix -> Alt+tab ctrl+R.
When debugging I can do that 50 times a minute. With my react app, I can do it maybe 5 times a minute. With my golang app I'm lucky if I can do it twice a minute.
As for react, I work with a medium sized code base in the hundreds of thousands of lines and all I have to do is alt tab since it hot reloads for me. Don’t see how PHP is any better since it isn’t even hot reloading. Also with react I can update css and it doesn’t lose the state which is nice for debugging style changes.
Not denying your point though. There is some real awful stuff out there that could make a grown man cry.
The human in the loop is a good thing. All things being equal, the type system is also a good thing, but what usually happens is that you end up checking your page once a minute or once every 10 minutes, not 50 times in a minute. That difference can make or break a project.
PHP has always been a powerful language where the burden of making it work properly 250% relies on the dev. Stuff like enums should significantly reduce that ratio, it’s a big deal I think.
On the debugging part, I found something like ruby’s pry to be the easiest and fastest option. I wish PHP had something similar.
It's probably part of the reason for the success of PHP and similar.
However, being able to have a "compile" step that does a lot of work to make things faster is also very useful. The key is being able to switch between them easily.
In PHP for example there is the code cache (added later but basically standard now), and assuming it's a web app you probably want to crunch the images and CSS in production.
One of the reasons I use golang where possible, I feel more productive in golang because any mistakes you are make are almost always logical issues with the code, rather than language error and usually works first time.
In interviewing, I've seen a few candidates re-run their application after making single statement changes. They'll rename a variable, re-run. Change a conditional, re-run. Introduce whitespace, re-run.
These people aren't even confident in renaming variables!
PHP enables this type of underestimation in your own abilities. You don't need to distrust yourself so much.
Don't think you have to do this.
That might be true, but sometimes it happens that you overestimated and introduced a breaking change 20 changes ago and now you have to rewind your steps back to find the exact place. If an iteration can be done in less than a second, it's probably cheaper (and less stressing) to just check every single change like this. This is what many coding editor integrations actually do for you.
I've even had IDE refactoring tools fail on me whilst doing this, in type checked Java codebases, with reflection in place and annotations, which predictably caused problems down the road. At this point, i'll take any and every method that can help me in development, especially in the face of meaningless cruft and unreasonable complexity.
I'm actually writing this in my 5 minute break after being stuck at work 1 hour past my official work hours, due to some stupid bug where one service ignores a client certificate from service A, but not from service B on the server in containers.
The opposite end of this spectrum (my current circumstances) is completely unreasonable IMO - a change in code needs an app recompilation and a push to the container registry before it's deployed on the server (cannot reproduce locally, possibly proxy configuration is to blame, but it's so simple it should not be possible), whereas configuration changes need the Ansible playbook to run to the end, which also takes time.
Thus, my feedback loop is ~10 minutes for seeing a new way in which the app will fail to do something supposedly simple. Even in normal circumstances, local app reboots still take at least a minute or so, since JRebel and code hotswapping just doesn't work a lot of the time with the frameworks we're using. I'd take being able to see the changes in my code every X seconds over every X minutes any day of the week.
Even if i trust myself, i still want that freedom and speed of development and checking why everything breaks.
>Edit file -> Alt+tab ctrl+R. Oops, Alt+tab fix -> Alt+tab ctrl+R.
Yeah, this is pretty much what the Common Lisp and Smalltalk people have been doing since mid 1980s. Except that they're not limited to web applications. And also python people to some extent, with ipython. And Haskell people with ghci.
The value of less friction cannot be overstated in coding work.
With PHP, you're not limited to web apps as well. The same rapid-fire style development can be applied when building CLI applications.
> When debugging I can do that 50 times a minute. With my react app, I can do it maybe 5 times a minute. With my golang app I'm lucky if I can do it twice a minute.
Hmm... when working on React stuff I don't even have to do the ctrl+R stuff. Hot reloading in the browser is a thing and works quite well. When working with Django it's very close to being the same as the PHP experience thanks to automatic server reloading. I worked with PHP extensively back in the day but I never miss the tight feedback loop (although maybe this experience is why I always make sure I have such a tight feedback loop in whatever I do, I guess you don't always get it by default).
The heart of PHP (not the standard library binding C libraries part) do have come a very long way. Even the things that look the same to you on surface have change under the hood and are way more performant thanks to it.
And by things I don't mean just web development.
The current limitations I see in PHP is that there is not an official multi-core coroutines solution.
God I wish that was true...
It's not that the language is necessarrily bad. It's the sludge of legacy code I've had to deal with and teams treating it as the hammer for every problem that they think they must treat as a nail.
Efficency be damned.
The nails are http requests and PHP is a damn good hammer.
Hello World
I know no other language that elegant.I do wonder if there really was value in salvaging PHP when we have a wealth of other languages and frameworks that do a perfectly fine job without any of the legacy mistakes sitting around.
The tales of legacy mistakes holding back php are things with no basis in reality. What legacy mistake holds php back? Method names/parameter ordering?
When I started with php in 2001 those elite programmers at meetups were looking down at php because Java was cool. In 2003 those elite programmers thought php should die because asp took over. PHP kept going along quietly taking over the web until the facebook movie came out making PHP cool for a moment. Those elite programmers decided PHP was too mainstream and the why PHP sucked movement started. The elite guys moved to Ruby On Rails then node/MongoDB, angularjs, React, Nextjs leaving each ecosystem for the next hoping that one day they will strike gold.
caching, jobs, docker via sail, authentication and authorization, one command to have a full multi team/tenant SaaS app template via jet stream.
even rails doesn't have this, as you need to choose your own implementation for auth and access control, something like sidekick for job queue etc....
plus the ecosystem. I've tried so hard to like other frameworks and some I really do (like remix.run) but the lack of real momentum and community hurts most anything else and just doing everything as serverless micro services isn't always preferred or using micro frameworks.
I'm excited for the new features and with octane you can get more reqs per second than Phoenix framework which should make it easier to scale apps with less resources.
Among that choice set, PHP is definitely the best contender.
1. The combination associative array/array data type is weird and I feel like the performance is not predictable unless you devote time to learning specifically about it
2. You're still stuck with all the weird legacy stuff, even if you don't use it, because someone else might bring it in
3. The OO stuff is basically like an old version of Java and a bit tedious to write. An IDE is definitely required
4. Many PHP developers formed their ideas about coding in the bad old days and will resist efforts to make code more testable or whatever because it's "too complicated."
The OO 'stuff' in PHP is far better. Notably, Traits, Statics and Testing.
Java (and JUnit) do not work well with static methods/classes, when it's unironically the most effective way to limit state. In PHP you can create a static class, that has static utility methods. Now you can ensure you have no side effects - unless accessing static properties somewhere, ofc. Then PHPUnit has no trouble helping you test these. It's a huge improvement over the acrobatics of booting up Spring to manage a singleton (which isn't the same thing as a static class) whenever you want access to those real static methods.
https://github.com/epiecs/phpmiko for connecting to devices and https://github.com/epiecs/mikodo for inventories and concurrency
The multi core coroutines comment is true but there are ways (to hack) around that.
The way I solved concurrency is just by forking and using sockets: https://github.com/epiecs/mikodo/blob/6bdcebe9fa7f44ffdedd82...
I use it at work atm does what it's supposed to. I also use Python as well but I wanted to know if it could be done in php :D
I’ve never learned to like the language, but have gotten pretty proficient with it. I don’t claim to be a PHP maven, though. I know that my style is fairly “primitive.”
I tend to use it for my backend work. It’s quite performant, has huge infrastructure support, and it’s entirely possible to write safe, high-quality, low-level systems in PHP. I’m a good engineer, and do a decent job; regardless of the tool I use.
C++ is the same way. People have been hating on that language for even longer than they have, PHP. C++ is still used for many major infrastructure projects, though; because it’s the best language for that kind of thing.
If you give a kid a chainsaw with the guard removed (as most arborists do), don’t be surprised, when the screaming starts.
No. Just no. PHP will not be solid and elegant by evolution. It might have become an excellent tool for the area it's supposed to be used in, but the only way it could ever become elegant is if it had its python2=>python3 sort of moment. They would need to break it to fix it.
I don't think they'll do that, since I think they understand that it doesn't matter at all that the language sucks.
The alternative would have to be TCL levels of bad to make me choose PHP.
If you can do as little as possible in PHP and rely on the low level functions to stitch together what you need, deserialize and render data in the front end, use front-end templating, then PHP is insanely fast, practical language.
The issues with PHP are usually when people build out giant frameworks in PHP, rather than using PHP as a higher level glue language for the built-in fast C functions.
PHP always wins when it comes to deployment and productivity. In my opinion that's the power of PHP.
It's also versatile. I used it for small projects, multi-million € projects, COM-port communication, API communication, prototyping and what not.
The syntax is not great, but to me PHP is this multi-tool that just gets the job done and will run reliable for years.
That's an interesting contrast to Python where the need to use "value = await fn()" v.s. "value = fn()" depending on whether or not that function is awaitable causes all kinds of API design complexity, all the way up to the existence of tools like https://github.com/python-trio/unasync which can code-generate the non-async version of a library from the async version.
result = fn()
if isawaitable(result):
result = await result
And turns out isawaitable is not that fast so things like GraphQL libraries that run above logic thousands of times per request get noticeably slow.I didn't realize it had a significant performance overhead though, I should look into that.
Sounds like an excellent way to create weird concurrency heisenbugs.
And, if we're being honest, the reality is that for that chunk that would break, most of them would either not have a developer on hand to fix it, or would be what I call a "Wordpress cowboy" who has a WP site they set up five years ago that they never update, and the sum total of their development experience is installing various WP plugins until the site vaguely does what they want it to do.
It's hard, because on one hand, if we didn't have things like Wordpress, then PHP would be in a position to undertake more breaking changes that would overall give the language and its libraries the much needed quality improvements. On the other hand, without things like Wordpress, it does become somewhat questionable as to whether PHP would have survived the dark days of PHP4 and the early versions of PHP5.
In saying all that, the work that the dev team have done to add great features and solid performance, alongside the community which has done a lot of good things like PSR's and the PHP League libraries to me, is one of the key things that makes PHP still an attractive environment to work in.
Originally GET/POST, cookie and environment values automatically became variables. This means page.php?id=123 gave you a variable $id. Along with no variable declarations, this was intuitive and was probably one of the reasons PHP was so popular with beginner developers. Unfortunately it was also the cause of untold numbers of security bugs, because people would write code like:
if (securityCheck()) { $isAdmin = true; }
//....
if ($isAdmin) {... }
Someone making the request page.php?isAdmin=true would totally bypass the intended check.So in April 2002, PHP 4.2 [1] was released that disabled this by default -- but so many (badly written) applications relied on this that it was not until March 2012 -- 10 years later! -- that PHP 5.4 [2] finally removed this option entirely.
Automattic is now more involved in PHP so hopefully that'll enable some collaboration
Are you talking about building an Android app?
I've built app in different Javascript frameworks. Angular, Vue, React.
If I was building a website I would use PHP over Python, Golang or Javascript frameworks because what you get out of the box doesn't compare.
Each language does something well. If I was building AI python would be my first choice.
Welp, guess all my Spring Boot web apps in Kotlin have actually been Android apps in disguise all this time..
I have used Kotlin for web services and, while I prefer Scala or plain Java for that, some of my colleagues prefer the Kotlin syntax and features.
> what you get out of the box doesn't compare.
Would you like to elaborate here? I have used Rails and Django and they get you a lot out of the box.
Because it's not possible to instantiate an enum, if one appears in the constructor of a class it'll break auto-wiring. I've written my own IoC containers and one fundamental assumption in them is that when class_exists returns true, it is what it says on the tin. Using a specialized factory would still be possible. I wonder if other containers would break on seeing enums as well, but I hope they fixed this because it's not mentioned in the breaking changes. The documentation for class_exists doesn't mention enum.
I wrote an indepth article about this: https://php.watch/versions/8.1/enums#enum-exists
There is an `enum_exists` function that only returns true for Enums. It's fairly unintuitive to combine class_exists with enum_exists to filter out Enums, I agree.
If you mean classes with private constructors, those are technically illegal. According to the PHP manual, constructors must be declared public. The fact that private constructors work at all should be considered an implementation detail.
Breakage occurs when something is said to be a class, yet isn't a class but still appears in the parameter list of a constructor. The container would instantiate a ReflectionClass of whatever is being requested and pass that around. At some point it'll call newInstanceArgs either with configuration-provided arguments or with auto-wired dependencies. The first case could still work, but foregoes auto-wiring.
I believe we are a few steps away from a fully builtin production ready server and db connection support.
I can see it being a boon for the esoteric stuff like ReactPHP, but for a regular MVC site it just seems like a unnecessary complication?
In JS land, it atleast makes interacting with the event loop and NOT blocking the UI thread easier.
Modern PHP might not have all the shiny features other high profile languages have, but it's getting there. It's slower than many would like because of much debt and legacy. But it'll get there.
Also, you can write shitty code in any language. I would bet that, if back then python was as easy to deploy, as PHP, we'd now be fighting about that the same way as we are about PHP.
I'm asking, because it was the hobbyists and kids who got started in PHP mucking around in their everyday white-label cPanel/Plesk-based web-hosting accounts in the very early 2000s that really gave PHP the mindshare of enthusiastic users and thus its staying power. But it's 2021 now: all the kids are getting started with NodeJS for server-side web-applications, not PHP.
With the decline of traditional web-hosting as something that people have and might experiment with (replaced at the low-end by Wix and Squarespace, and major "Cloud" providers at the high-end), what opportunities does PHP have to attract new eyeballs?
Years ago self-hosted WordPress and phpBB installs would have been been a good gateway, but both of those are going out of fashion owing to the substantial maintenance burden that comes with self-hosting. Everyone I know that used to self-host WordPress (former clients, friends, local small businesses, etc) have all given-up and switched to WordPress.com's managed-hosting model or gone with the aforementioned Wix and Squarespace.
Ultimately PHP as-we-know-it will last as long as Zend (UPDATE: it's now owned by Perforce?!? wow...) can secure sales/support funding, which is predicated on their continued penetration of major enterprise customers - or indirectly through the continued popularity of WordPress and the like, even if it's hardly ever self-hosted anymore.
Personally, my money's on maybe 5-10 years' continued credibility, and then another 15 years of slow decline into irrelevance.
Announcement
https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundati...
PHP Foundation
https://opencollective.com/phpfoundation
Accepts donations to help the development of PHP.
Promises, async and await in javascript, coroutines and threads in kotlin, fibers in some language runtime (including this php 8.1 [0]), single process (nodejs), multi-process(php-fpm worker), single-thread, multi-thread, goroutines in go, multi-core coroutines
Googling the definitions and x vs y situation helps a little, the main confusion to me is why some people want this xyz feature in a language runtime and not the other, the pros and cons are seriously so confusing
I have probably used several, like promises, async, await, like others said async would be implement on fibers [1] (is php 8.1 implementation same as V8,spidermonkey,javascriptcore? or any other language runtime). And I have tried to understand kotlin coroutines as well
modern times to run php, people would use php-fpm with nginx, it is running multiple worker (single) process, so why would anyone [2], [3] wants multi-core coroutines in it? What does it even mean?
Writing this out ease my mind a bit yea, need to be able to communicate the confusion instead of just saying "programming is difficult"
[0]: https://news.ycombinator.com/item?id=29343773
[1]: https://news.ycombinator.com/item?id=29344427
Not everyone does. There's also https://reactphp.org (which is an event loop runtime, similar to Node), and https://amphp.org (also event loops), and Swoole https://github.com/swoole/swoole-src (coroutine runtime, similar to Go).
Fibers are basically an API that event-loop runtime libs can use so that userland code doesn't need to use promises or generators to run non-blocking operations. Fibers are not useful for php-fpm or swoole users.
On the other hand, though, PHP’s always tended to be a borrowing language that accumulates features from elsewhere, so there probably is some TS influence.
Also I hope we'll get generics at some point. I know there are some issues with their implementation, but even non-runtime enforced generics would be better then relying on a docBlock annotation.
Enums are neat, though.
class User
{
/**
* @Assert\All({
* @Assert\NotNull,
* @Assert\Length(min=5)
* })
*/
public string $name = '';
}
PHP 8.1
class User
{
#[\Assert\All(
new \Assert\NotNull,
new \Assert\Length(min: 6))
]
public string $name = '';
}Very similar to Java annotations.
That piece of code is about data validation.
See more at https://www.php.net/manual/en/language.attributes.overview.p...
https://front-line-php.com/cheat-sheet
It’s covered under “Attributes”.
I use it constantly not because it's well-designed but because TINA (there is no alternative).
[] == ![]; // true. Go ahead. Run it in your console...
* it has its quirks but we know them and each newer version fix more of them.
* its damn fast (more than python or ruby)
* its type system is better than python (trait/interface , union type <3 , and now intersection type ! )
* symfony/laravel have evolved over the last 10 years, most of the things you knew 10 years ago are still true now
and as a result it tends to attract people with the same mentality, my experience with recruiting php developer is that you have a much clearer clivage of "wordpress website maintainer" and "people who want to get shit done"you will not find for example "genius developer, that write code faster than you think, who writes all his project in rust but is now thinking to switch to haskell and will leave your company as soon as it find a company that use it"
Take our company for example, our flagship web product was developed more than a decade ago, and, well, today we still use PHP, because rewriting everything in a different language is a gargantuan task. It's not only about the language itself, but also about all the tooling/best practices etc. around it, which you have to replace, and it's costly. We do gradually modernize our code to remove all the PHP5-era warts, and it's much easier to accomplish than switch to a different language entirely. Modern PHP7+ with Symfony is very pleasant to work with, and in my opinion, from the productivity standpoint, there's really no reason to switch to anything else. Also, PHP7+ seems to be faster than Python/Ruby in raw interpreter speed. However, we realized that we can't scale further if we stay with our PHP/Symfony monolith for everything because of Symfony's considerable startup overhead, so we now try to write new services in Go (request processing is usually 10 times faster for our loads), and seems like the combo PHP+Go is very popular among PHP developers in general.
So, I'd say, PHP isn't "dead" and is still widely used in 2021, however, in my opinion, its usage is indeed dwindling, because there seems to be a trend even in our own PHP community to gradually supplement/replace/augment parts of our projects with services written in Go, and PHP is more and more frequently equaled to "legacy"/"monolith".
PHP has become better and better over the years!