PHP has been good for years. At the same time, old, unsupported, terminally insecure PHP versions have become the IE6 of backend development. If you learn PHP and want to use that skill for money you have to be super duper extra careful not to end up working on one of these legacy backends, and they are LEGION. There are tens of thousands of company/corporate sites running PHP versions that haven't seen a security update in over a decade. 😨
any time i see such an app i feel like it's better to just rebuild it with Laravel and the latest PHP version. the code is probably shit anyways so just extract the business requirements and ignore the old code as much as you can.
I already modernized 2 companies from 5.x to 7.x (few years ago) and 8.x (also some while ago). And to be really honest: I like cleaning up. Especially the first part was a HUGE mess. It was php building html pages with embedded javascript using objects, dynamically created inline in . It was .... marvelous :D
@@TNeulaender oh man, I love seeing vuejs components with a bit of jQuery and PHP all intertwined. It's the worst. PHP 8 is glorious. It's a lot better than JS
Just never take a "PHP" job, only Symfony/Laravel jobs. There is not much to learn about PHP specifically anyway, you are mostly learning frameworks not language itself.
@@Rakkoonn then it's the same with Java at least. who builds Java web apps without Spring or that other framework? there are "PHP" jobs. we literally have a position open for that at the company i work in. it's a DIY-ed PHP web app - no framework. (it also sucks but that's not relevant to the point)
@@ThePrimeTimeagen Try Symfony. Or if you try Laravel try to not to use ambient context (instead of dependency injection) as much as the docs encourage.
The clone stuff is actually brilliant. It's for immutability. Suppose you have a readonly class. You can have its properties be public and readonly - so no getters. But before PHP 8.3, you could not derive new copies of instances of readonly classes, unless you go through the constructor. So now we can have a class with immutable methods that can efficiently generate cloned derivations. Ex: $user->withName("New name"); Internally, `withName()` would clone $this and update the name property on the cloned instance.
Yeah I wonder if the example on the PHP release announcement is the best example. Something like what you're showing with a `wither` method might be clearer.
Unfortunately, it's not like that. You can't modify the name property from the withName method. The only place that allows modification of readonly properties is the magic __clone method, which you can't pass any data to.
@@Betacak3 Yeah. I guess you could do some hack thing like stuffing the data into a private static property for __clone to pull it out and know what to modify, relying on the fact that PHP is effectively single threaded. Would be ugly but might work fine if you don't have to read the implementation too often.
@@barneylaurance1865 You can't do that either. On a readonly class, everything is automatically readonly, including static properties. But static properties can't be readonly, which makes sense, because at that point they'd just be class constants. So declaring a static property in a readonly class is actually an error. Out of curiosity, I tried modifying the new instance with reflection, but even that doesn't work. I actually see no way to make wither methods for readonly classes with what we have right now.
@@Betacak3 Oh yeah I forgot about that restriction. You'd have to make a second class to hold those static properties. Optionally then the statics could be done via a WeakMap so you have one per instance instead of just one for the object being cloned currently.
PHP still has the most potential in its Foreign Function Interface, as the language was designed with that in mind in the first place. It’s a shame they do not focus more on making that part of the language more user friendly.
Random note, a theory on why the PHP namespace delimiter is `\` is because the foreard slash `/` was already the division operator so it was easier at the time to drop the backslash into the parser. Similar reason as to why it didn't use the `::` operator C++ uses, since it was already in use for static calls.
If i do understand correctly, that static call is a method defined on classs and not on instance, isn't this exactly how rust uses "::"? use std::collections::HashMap; let m = HashMap::new(); So it's possible to have semicolons for both things(?)
@@mihalious the most part yeah. But PHP's parser is different from Rust, and it's got a lot of legacy/BC cruft going on. They could have made it do both and be more contextually aware, but that's just not how it played out historically unfortunately. Fast forward like 14 years now and if you swap it out you break the ecosystem.
actually... it was a whole stuff itself back in the days. look up for "php rfc namespace separator" for more info. in the footnote, there's also the full chat history about why they ruled out `::` ns separator (hint: T_PAAMAYIM_NEKUDOTAYIM)
I really do wonder whether Prime would like Laravel or not. IMO Laravel is an antithesis to anyone who likes Go. Go is all about simplicity while Laravel is all magic and abstractions upon abstractions. I would say Laravel is more akin to React or Next.js specifically in that in React/Next.js you are not writing just plain JS, but the React way of writing JS. Similarly, Laravel is not really PHP at this point, but almost like its own language built on top of PHP. Also, just as there are many people who learn React before they learn vanilla JS, there are also many people who jump straight into Laravel without bothering to master PHP and I don't think that is a good thing in either case
That's just a problem with frameworks and people trying to get a job. The framework is there to help the experienced programmers first and foremost. The inexperienced ones are expected to get up to speed on the framework because that's what the company uses. So there's not much time/incentive to master the language first and learn the framework second.
What are you talking about? Out of Big 3 frontend frameworks React is closest to writing vanilla JS, that's why it's pretty easy to slap on typescript (which also supports react templates out of the box) and get all static analysis goodies. You will get the same problems of synchronising state with views, along with reinventing component functions and some kind of declarative way to describe components even in 100% vanilla JS, anyway. Writing basic DOM manipulation boilerplate becomes annoying pretty fast, especially for hybrid render contexts, let alone when you want to change some logic.
He's laying the groundwork, a good move to avoid unnecessary criticism from individuals who haven't touched PHP in decades but still feel compelled to comment and assert their relevance.
I became a dev in 2019 and in 2020 we had to use PHP for the first time. Even "back then" we still were corrected that PHP is not that slow thing it gets the rep for. Just like Java and C# there were plenty of perf optimizations over the years. Now I personally cannot prove it but I trust the people who told me. Also the project we did ran pretty flawless under PHP. Tho I never really got involved with PHP again :D
It is by far slower than other languages. But it usually doesn't matter as the bottleneck isn't PHP but other things like the DB. Also it really depends on what you do. If you create the next whatsapp which will be used by billions of people, PHP is probably not the right choice. If you make some Business Solution for some thousands of users I would say, why not.
It's slower than most languagues, but I would argue that it's the fastest of the interpreted ones (PHP, Python, JS, Ruby), at least for raw performance. For async stuff, JS still holds the edge. Multithreading though, not sure.
PHP is really great for small to medium projects...even big projects if you configure it well...Also Laravel + InertiaJS is a gamechanger...And for those who say PHP is slow, how many users do you have?
Just as a noob, what makes a language ideal for large projects as opposed to medium/small projects? Is it just in the case of avoiding bugs in a language like java where things are really verbose and harder to write errors in?
@@trentirvin2008 The easiness to slap static analysis on (so you could catch basic errors even before building the code) and the amount of legacy interfaces you have to interact with. Java is more about having a compiler without memory wrangling of C/C++, rather than boilerplate. All three relevant dynamic languages: Python, Javascript and PHP have promoted pretty nasty practices in the past and left a lot of legacy unworkable code around (and even some built-in interfaces lingering to this day) thanks to the lack of static analysis tools.
@@ra2enjoyer708I still use non static typed languages for all my projects. In 20 years of programming I never saw python or php misuse a variable because of dynamic typing and if an interface is documented I explicitly cast the type. I leave static analysis and industry standards to philosophers that don't have to program for a living
Really love your content. Although I have to play it at half speed at times, to understand what you are saying (or play it more than once :) ). Keep up the great work!
One reason I can think of for doing this is cloning ORM models and you want to clone the table row but change the ID on the model internally. This way you don't have to move data between the database and the API server.
It really is just a solution to the always-pass-objects-by-reference problem. A cloned object that had other objects as properties would contain references to the original objects rather than new copies. So in PHP world, this was handled via "deep cloning", i.e., in the __clone method, you clone your objects as well. But that wasn't possible on readonly classes/properties until 8.3
The deep clone of read only seems like a way to ensure that your clone does not reference a read only property. It makes a whole new one, and since it's wholly new you can alter the field before it's actually instantiated with read only. If you deep cloned an object with 12 properties, 3 of them are nested read only objects, and one of those read only objects has a value that needs to change-that's where the new feature helps. Since you're only altering one of the nested objects, it can reference the ones that aren't changed and make a new object for the ones that do change. I imagine having a user update their information, but wanting to ensure that it doesn't accidentally get updated elsewhere, is a use case. But I'm a noob and have no idea.
Laravel developer experience is way better than rolling your own thing with node, go or python. It's crazy how much more you can get done in the same amount of time.
i disagree. the DX can be pretty bad due to magic/generated methods, e.g. on VSCode. i've only seen PHPstorm handle that decently well. meanwhile the DX with tRPC remains unmatched.
Laravel is the best framework. These NextJS kids don't even know what they're missing. All the shitty services that they have to pay for that Laravel has built in :0
@FunctionGermany tRPC is not a framework, you still have to figure out authentication, permission management, configuration, databases, caching, environments and more. PhpStorm handles it well by default and there's a very good paid plugin that fills in the gaps with model properties and auto-generated hints for the rest of the methods. There's also packages that let you add the properties with static types to your models if you want to do that.
I completely disagree with the Go part, a dynamic language + framework full of magic will never be as good as a simple and explicit one. Having to write more things is totally worth in the long run
@@spicynoodle7419 there's a lot of SaaS nonesense going around in the JS space but you can actually ignore it and build something independent with next.js too. it's just that nobody is talking about it because there's no sponsorship money in a FOSS project.
For the cloning of readonly one, deep cloning could not be done before. For those that don't understand this concept, because PHP passes all objects (i.e., class instances) around by reference, if when cloning, you don't also clone the underlying object and re-assign on the newly formed object, then it will still be pointing to the old one, which means if that is then mutable and mutated, it will essentially mutate it in all clones. In the example provided, the PHP class is mutable, so if you didn't reassign the internal ->php on clone, but then cloned the Foo object and then modified the php version, like in the 8.3 version, then the original Foo object you cloned from has the same value. Now, with the 8.3 example, modifying the $clonesd->php->version does not modify it for $instance->php->version. In 8.2 this wasn't possible. I hope that's clear?
Groovy, now all I have to do is make sure that my WordPress clients that I'm unable to manually adjust server settings of due to hosting restrictions that have had their sites working for years don't break due to plugins auto-updating without my knowledge before I get a chance to vet them, or worse - plugins that haven't been updated for a while but are still useful suddenly being considered unusable due to newly deprecated PHP functionality that either I'll have to wait for updates, find alternatives for, or hack in the updates myself.
PHP uses '\' (backspace) as namespace delimiter because '.' (dot) is already used for string concatenation.. I remember this clearly when it got introduced, because that was the drop that filled my bucket and made me abandon PHP. But traits and the new stuff looks damn tempting...
I work with PHP regularly, it's usually a pretty nice experience as long as I'm just building new stuff. Delving into the old stuff is usually painful, but that has more to do with the overall architecture and loads of ugly fixes that you need to keep in mind 10 files away in order to not break shit. That along with an overall reluctance of using classes for loads of things, meaning you have documentation which says "returned array has these keys" but does in fact not have those keys.
The short-term mutability of a deep-cloned, readonly object seems really nice. In JS you'd have to do something like > const x = { ...data, nested: { ...data.nested, foo: 123 } }; whereas Elixir would have something like > x = put_in(data, [:nested, :foo], 123) So this seems pretty similar to the latter. Looks neat.
PHP has grown up, but not everyone’s programming skills have kept pace. Let’s give credit where it’s due: PHP's not the problem, it's waiting for some programmers to catch up! But they still keep hating lmao
PHP hasn't been the problem since v7 i'd say. however, PHP suffers heavily from what i call the PHP-bootstrap-jQuery-syndrome which is when a technology is so accessible that it attracts many inexperienced and untrained developers, resulting in the majority of code written with that technology being very low quality, therefore giving that technology a bad name.
@@P8860 don't feel attack. there must be technologies that a lot of junior devs use, otherwise we'd have a lot less software developers today. pretty much all developers need to write a lot of bad code as a byproduct before they can make anything good.
Bro, PHP namespaces has been around since v5.3 I think, that's like some 15 years ago. Those slashes has meaning in auto loading classes via Composer. I think your idea of PHP as "garbage" is extremely outdated. Seems to me your idea of PHP is still in the v4 era -- where PHP was ironically king because everything else actually suck. Now I've no hate for Laravel but even that doesn't represent how really different and good PHP is now. Just plain PHP + PSR + Composer libraries cuts it on its own. If you really want to use a framework, Symfony is a good choice -- less magical and closer to native PHP. You have to try modern PHP and you'll see, but don't just go blindly and write in procedural PHP 4 like you used to. At least read on PHP The Right Way and you're good to go.
5:47 as someone who has written PHP near daily since the ye ol' PHP3 days.. I don't get the deep cloning situation. I can't even think of a scenario where I'd find myself in where that'd be a useful or even desirable thing to do
I'm guessing it's an optimization for things like PSR-7 objects, which are meant to be immutable so every time you mutate one, it hands you back a brand new object with cloned data instead.
I've understood the example for deep cloning magic properties now. Yes the final line on the 8.3 side is outside the magic clone method. But that's not where the fatal error is. The fatal error in 8.2 happens on the last line on the left, where `clone` invokes the Foo::__clone method. And clone is needed because although Foo is readonly, the PHP class is not readonly, and has a mutable property. So when making a clone of the Foo object we want a deep clone, that has its own instance of PHP, instead of sharing the instance with the original object. It's a confusing example with an immutable object that contains a reference to a mutable object.
5:51 - That exists since if you have a read-only property on a class (like “Foo” in this case) that you want to clone, you can’t do a _deep clone_ because that property cannot be updated to be cloned as well (hence the “deep” clone of the lower down references). This update fixes that I guess.
7:19 the had a better namespace separator when they first introduced the concept, but then they changed it to a / at the last. I think the separator was ::, which is used to access static members.
PHP always passes objects by reference so cloning an object with a readonly object property will have the cloned object have an readonly object property referencing the same readonly object as the previous one. So by making a clone of the readonly object property in the magic __clone method prevent the side effects of modifying something in the readonly property and making the program go funny (that being the same referenced object in both the original and cloned instance)
3:45 - In PHP, everything is copy-on-write references, if passed "by value". There's no syntax to get a reference, what you can do is force the creation of aliases that act as references [using the =& operator]. You can also declare a parameter as "receiving a reference", which is actually pretty bad, because the user never knows their variable could potentially be used as a output parameter, so it is better avoided. eg: you can function abc(&$var) { $var = 0; }, when you call it abc($input), input will become 0 even if you never expected it to be a reference pass. For the clone, readonly props can only be modified inside the constructor. That change makes it possible for you to reinitialize readonly stuff after a clone, if necessary. Not sure I like it, but that's what it is.
@@GreyDeathVaccine I have no problems with passing stuff by reference, my problem is when you're passing an argument that you don't expect to become magically a reference, say an integer, and the function changes that argument to whatever crazy stuff it wants to change it to. Usually not a problem with std api, but users are crazy. In PHP you also have 0 visibility over what parameters are going to be by-reference and what parameters are going to be by-value, from the function user side. Also, since php tends to be copy-on-write everything, there's usually not a whole lot of stuff that you actually want to pass by-reference anyway...
@@barneylaurance1865 Exactly! Assume you have 2 functions: function a($v) { $v->foo = 0; } function b(&$v) { $v = 0; } Then you have a value: $c = new Something. if I call a($c), I wouldn't be surprised by something changing inside it, but $c itself is still the reference to that obj. Now if I call b($c), it's a footgun that has just destroyed any hopes that I can debug this shit in less than a day. $c isn't the reference anymore, $c is something else entirely. It's passing a reference as a reference and the user of the function has NO IDEA that that happened.
I think they put too much emphasis on being able to deep clone readonly properties with that explanation. I think the bigger deal is being able to modify cloned, readonly properties period, not necessarily for the purpose of deep cloning them. Otherwise the cloned object can never have different values for the readonly properties. I think this is a good stepping stone to further improvements in the future if they add something like `clone with` where you specify which properties of the clone should have new/different values. You can do something similar in Kotlin and Scala 3. It's great for making immutable classes because if everything is immutable, how do you change anything? Well you don't change the object, you clone it with differences. Currently you basically have to duplicate the constructor in a hand rolled cloneWith() method for every single class you make.
Everyone hating on PHP has obviously never built anything with Laravel and they don’t know what they’re missing out on 😔 best developer experience and community I’ve ever experienced.
Php is getting better. For people already using php, all these improvements are very nice to get. But php will always be worse than a nice, well designed, statically typed, compiled language. Comparing PHPStan or Psalm to a real compiler and the way it reports issues is night and day. Php static analyzers are not part of the language, they are these tacked on things made by the community, and therefore will never be as nice as a compiler that is required and part of the language. Also, php is overly verbose. `readonly`, arrows just to call a method, a dollar sign before every variable. Those might seem like small things, but it all adds up. Compare it to a language like Scala 3 where it is both terse and expressive/readable at the same time.
2:30 : Backslash is the separator for namespaces. Similar to how a "." would be on a Node package name. 3:08 : Not a huge fan of the #[\Override] annotation but It would make maintaining stuff probably a bit easier. I don't understand why we couldn't just have a PHPDoc @override comment instead. That whay The Language Server could do the same checks. By using an annotation, PHP now has to check this stuff, whenever it loads a script.
@@ivanjelenic5627 The Problem I see here, is, that it uses the # symbol, which does make it a comment already. But it is a comment, that is now executed / evaluated at runtime instead of just during writting in the IDE. With PHPDoc it would be something like /** @overrides [propertyname] */
PHP didn't used to break backwards, which was the problem with the language for a long time. There'd be old stuff they'd mark as "deprecated" but people would still use it. Now they brokeback... 😏
They try to keep most of the BC breaks for the x.0 major releases, i.e. they're saving up thing to break in 9.0. But there are always a few BC breaks in the x.y releases like this year's.
PHP is badass. I have made several applications using PHP and laravel and they are beautiful, fast websites. PHP is awesome but can be slower than JS. If you use a redis DB for sessions and caches, your php laravel site doubles in speed. Using a garbage collector makes it even faster!
Backward compatibility breaks in minor versions is stupid, they should just follow good old .. version scheme. I like the new features PHP is getting, but they should really wipe out the inconsistency in the language, that would be a great breaking change worth another major version.
some projects have their reasons for not following semver. maybe regular, smaller breaking changes motivates more teams to update in comparison to major breaking updates which creates demand for supporting the old version or LTS versions.
@@SXsoft99 sure, that may be the case. To avoid having to know such internals, e.g. as an administrator, it is nice to follow the versioning rules. After all, that's the whole point.
PHP namespaces resembles the folder structure of the file. Why they use \ \ \, its because you can have 2 functions with same name but different namespace. So you can import both functions but just point to right namespaces. You than need to use as word to rename inports from namespace.. bla bla
I'd used PHP lots back in 2000, I'd stopped using awk grep, etc. in command line tools! But nah, I'm sorry, not interested. And yes, I still use good'ol bash. Never need awk as much as used to though ... funny that. I suppose data system integrations are better.
You clone the const to a new instance, change its value and then it is locked as the const that it is? You get one free change of value at time of cloning, and then that's it, locked?
Been trying to learn PHP since PHP 5, now was trying to learn PHP8, now it’s gone to PHP 8.3 before I could get used to PHP8……. The tech is coming out and updates are so fast nowadays how can anyone keep up?!?!?
By sticking to the technologies you chose for a project for as long as it's reasonable to do so, and not changing the minute a new version/framework comes out. I don't think PHP8 is irrelevant just because 8.3 came out.
@@wolizuka nobody is looking for someone hood in PHP 5, when PHP 8.3 is out…. Same with PHP 8…. As new tech comes out that’s what these jobs want to hire people who have mastered the newest tech
5.6 28-Aug-14 7 3 December 2015 7.1 01 December 2016 7.2 30 November 2017 7.3 6 December 2018 7.4 28 November 2019 8 26 November 2020 8.1 25 November 2021 8.2 8 December 2022 8.3 23 November 2023 how were you not able to keep up? one year is enough to check what's new and refactor the code
@@TheBlackmanIsGod that's just not true? a hefty amount of jobs orbit around maintaining existing code, which is often a few if not several versions behind whatever is the latest thing. As long as there are no security fixes which haven't been backported, there's virtually no reason to update other than improved DX when it comes to established languages. All of that said, it is quite the exaggeration to say "how can anyone keep up" when few things have been actually added, none of these changes have been paradigm--shifting or anything of the sort and in reality there hasn't been any fundamental changes to the language so if you know PHP 5, you're 95% of the way there to PHP 8
Nonsense. First of all 99% of the language remains the same. Second of all you don't need to know everything, just know it exists and look it up when you need it.
I don't know if it applies to php as well but in c++ you might want to deep copy a const ref if you want to ensure your copy isn't changed by the source since it might be a non const passed as a const. It could also be the you want to store it in a specific location
@@martinhotmann7868 superior ecosystem. You can't go wrong with Laravel but if you feel like something different there's also Symfony, that's kinda about it for the majority of devs. You don't have to play catch-up with every other framework trying to reinvent the wheel, or completely changing paradigms between versions
PHP was never backward compatible and that's why it's a pain in the ass to update Laravel projects, which in itself isn't 100% backward compatible either lol.
PHP has been good for years.
At the same time, old, unsupported, terminally insecure PHP versions have become the IE6 of backend development.
If you learn PHP and want to use that skill for money you have to be super duper extra careful not to end up working on one of these legacy backends, and they are LEGION.
There are tens of thousands of company/corporate sites running PHP versions that haven't seen a security update in over a decade. 😨
any time i see such an app i feel like it's better to just rebuild it with Laravel and the latest PHP version. the code is probably shit anyways so just extract the business requirements and ignore the old code as much as you can.
I already modernized 2 companies from 5.x to 7.x (few years ago) and 8.x (also some while ago). And to be really honest: I like cleaning up.
Especially the first part was a HUGE mess. It was php building html pages with embedded javascript using objects, dynamically created inline in . It was .... marvelous :D
@@TNeulaender oh man, I love seeing vuejs components with a bit of jQuery and PHP all intertwined. It's the worst. PHP 8 is glorious. It's a lot better than JS
Just never take a "PHP" job, only Symfony/Laravel jobs. There is not much to learn about PHP specifically anyway, you are mostly learning frameworks not language itself.
@@Rakkoonn then it's the same with Java at least. who builds Java web apps without Spring or that other framework?
there are "PHP" jobs. we literally have a position open for that at the company i work in. it's a DIY-ed PHP web app - no framework. (it also sucks but that's not relevant to the point)
Php is actually fine now. it's not the most flashy or modern experience but it's good enough. Pair it with laravel and it does a lot of things right.
PHP pays my bills just fine :)
i want to try laravel
@@ThePrimeTimeagenplease try asp for our amusement 😂, we like see you suffer 😂
Please make it into a video or I will send you a lexer in php. Take it as a threath @@ThePrimeTimeagen
@@ThePrimeTimeagen Try Symfony. Or if you try Laravel try to not to use ambient context (instead of dependency injection) as much as the docs encourage.
The clone stuff is actually brilliant. It's for immutability.
Suppose you have a readonly class. You can have its properties be public and readonly - so no getters. But before PHP 8.3, you could not derive new copies of instances of readonly classes, unless you go through the constructor.
So now we can have a class with immutable methods that can efficiently generate cloned derivations.
Ex: $user->withName("New name");
Internally, `withName()` would clone $this and update the name property on the cloned instance.
Yeah I wonder if the example on the PHP release announcement is the best example. Something like what you're showing with a `wither` method might be clearer.
Unfortunately, it's not like that. You can't modify the name property from the withName method. The only place that allows modification of readonly properties is the magic __clone method, which you can't pass any data to.
@@Betacak3 Yeah. I guess you could do some hack thing like stuffing the data into a private static property for __clone to pull it out and know what to modify, relying on the fact that PHP is effectively single threaded. Would be ugly but might work fine if you don't have to read the implementation too often.
@@barneylaurance1865 You can't do that either. On a readonly class, everything is automatically readonly, including static properties. But static properties can't be readonly, which makes sense, because at that point they'd just be class constants. So declaring a static property in a readonly class is actually an error.
Out of curiosity, I tried modifying the new instance with reflection, but even that doesn't work. I actually see no way to make wither methods for readonly classes with what we have right now.
@@Betacak3 Oh yeah I forgot about that restriction. You'd have to make a second class to hold those static properties. Optionally then the statics could be done via a WeakMap so you have one per instance instead of just one for the object being cloned currently.
PHP still has the most potential in its Foreign Function Interface, as the language was designed with that in mind in the first place. It’s a shame they do not focus more on making that part of the language more user friendly.
Random note, a theory on why the PHP namespace delimiter is `\` is because the foreard slash `/` was already the division operator so it was easier at the time to drop the backslash into the parser.
Similar reason as to why it didn't use the `::` operator C++ uses, since it was already in use for static calls.
If i do understand correctly, that static call is a method defined on classs and not on instance, isn't this exactly how rust uses "::"?
use std::collections::HashMap;
let m = HashMap::new();
So it's possible to have semicolons for both things(?)
They went LaTeX mode
They could not use `.` as a delimiter as well because it is reserved for string concatenation in PHP.
@@mihalious the most part yeah. But PHP's parser is different from Rust, and it's got a lot of legacy/BC cruft going on. They could have made it do both and be more contextually aware, but that's just not how it played out historically unfortunately.
Fast forward like 14 years now and if you swap it out you break the ecosystem.
actually... it was a whole stuff itself back in the days. look up for "php rfc namespace separator" for more info. in the footnote, there's also the full chat history about why they ruled out `::` ns separator (hint: T_PAAMAYIM_NEKUDOTAYIM)
I really do wonder whether Prime would like Laravel or not. IMO Laravel is an antithesis to anyone who likes Go. Go is all about simplicity while Laravel is all magic and abstractions upon abstractions. I would say Laravel is more akin to React or Next.js specifically in that in React/Next.js you are not writing just plain JS, but the React way of writing JS. Similarly, Laravel is not really PHP at this point, but almost like its own language built on top of PHP. Also, just as there are many people who learn React before they learn vanilla JS, there are also many people who jump straight into Laravel without bothering to master PHP and I don't think that is a good thing in either case
Agree, i started with laravel 3 and thought i knew php until i applied for senior php dev position and found out that i knew nothing
That's just a problem with frameworks and people trying to get a job. The framework is there to help the experienced programmers first and foremost. The inexperienced ones are expected to get up to speed on the framework because that's what the company uses. So there's not much time/incentive to master the language first and learn the framework second.
What are you talking about? Out of Big 3 frontend frameworks React is closest to writing vanilla JS, that's why it's pretty easy to slap on typescript (which also supports react templates out of the box) and get all static analysis goodies.
You will get the same problems of synchronising state with views, along with reinventing component functions and some kind of declarative way to describe components even in 100% vanilla JS, anyway. Writing basic DOM manipulation boilerplate becomes annoying pretty fast, especially for hybrid render contexts, let alone when you want to change some logic.
Nette Framework is the way :)
Nah, any time you want to write an algorithm or calculation etc it's going to be vanilla PHP with some Laravel stuff thrown in where necessary.
I can feel how Prime wants to do a serious project on Laravel.
wait until he reads about Livewire and compares it to htmx
He's laying the groundwork, a good move to avoid unnecessary criticism from individuals who haven't touched PHP in decades but still feel compelled to comment and assert their relevance.
PHP isn’t fast like Go or C or Rust, but it is often sufficient, and the tooling is great.
@@JeremyAndersonBoise It's fast enough for most things. Depends more on version and how you do things.
Imagine when Prime finds out about Swoole.
If javascript can be used for writing backends, its time that php gets used for making frontends
stop
Heck, you can use CSS as a backend language. So, why not. 😀
This is so good
PHP is frontend bro . Looks like React nowadays
Livewire already kinda does that
I became a dev in 2019 and in 2020 we had to use PHP for the first time. Even "back then" we still were corrected that PHP is not that slow thing it gets the rep for. Just like Java and C# there were plenty of perf optimizations over the years. Now I personally cannot prove it but I trust the people who told me. Also the project we did ran pretty flawless under PHP. Tho I never really got involved with PHP again :D
It is by far slower than other languages. But it usually doesn't matter as the bottleneck isn't PHP but other things like the DB. Also it really depends on what you do. If you create the next whatsapp which will be used by billions of people, PHP is probably not the right choice. If you make some Business Solution for some thousands of users I would say, why not.
It's slower than most languagues, but I would argue that it's the fastest of the interpreted ones (PHP, Python, JS, Ruby), at least for raw performance. For async stuff, JS still holds the edge. Multithreading though, not sure.
Sounds like the deep clone is for updating immutability. So you can change, dump the old object, and move forward with the new.
PHP is really great for small to medium projects...even big projects if you configure it well...Also Laravel + InertiaJS is a gamechanger...And for those who say PHP is slow, how many users do you have?
Just as a noob, what makes a language ideal for large projects as opposed to medium/small projects? Is it just in the case of avoiding bugs in a language like java where things are really verbose and harder to write errors in?
@@trentirvin2008 The easiness to slap static analysis on (so you could catch basic errors even before building the code) and the amount of legacy interfaces you have to interact with. Java is more about having a compiler without memory wrangling of C/C++, rather than boilerplate. All three relevant dynamic languages: Python, Javascript and PHP have promoted pretty nasty practices in the past and left a lot of legacy unworkable code around (and even some built-in interfaces lingering to this day) thanks to the lack of static analysis tools.
@@ra2enjoyer708I still use non static typed languages for all my projects. In 20 years of programming I never saw python or php misuse a variable because of dynamic typing and if an interface is documented I explicitly cast the type. I leave static analysis and industry standards to philosophers that don't have to program for a living
Really love your content. Although I have to play it at half speed at times, to understand what you are saying (or play it more than once :) ). Keep up the great work!
One reason I can think of for doing this is cloning ORM models and you want to clone the table row but change the ID on the model internally. This way you don't have to move data between the database and the API server.
I was thinking the same
It really is just a solution to the always-pass-objects-by-reference problem. A cloned object that had other objects as properties would contain references to the original objects rather than new copies. So in PHP world, this was handled via "deep cloning", i.e., in the __clone method, you clone your objects as well. But that wasn't possible on readonly classes/properties until 8.3
The deep clone of read only seems like a way to ensure that your clone does not reference a read only property. It makes a whole new one, and since it's wholly new you can alter the field before it's actually instantiated with read only.
If you deep cloned an object with 12 properties, 3 of them are nested read only objects, and one of those read only objects has a value that needs to change-that's where the new feature helps. Since you're only altering one of the nested objects, it can reference the ones that aren't changed and make a new object for the ones that do change.
I imagine having a user update their information, but wanting to ensure that it doesn't accidentally get updated elsewhere, is a use case. But I'm a noob and have no idea.
Laravel developer experience is way better than rolling your own thing with node, go or python. It's crazy how much more you can get done in the same amount of time.
i disagree. the DX can be pretty bad due to magic/generated methods, e.g. on VSCode. i've only seen PHPstorm handle that decently well.
meanwhile the DX with tRPC remains unmatched.
Laravel is the best framework. These NextJS kids don't even know what they're missing. All the shitty services that they have to pay for that Laravel has built in :0
@FunctionGermany tRPC is not a framework, you still have to figure out authentication, permission management, configuration, databases, caching, environments and more. PhpStorm handles it well by default and there's a very good paid plugin that fills in the gaps with model properties and auto-generated hints for the rest of the methods. There's also packages that let you add the properties with static types to your models if you want to do that.
I completely disagree with the Go part, a dynamic language + framework full of magic will never be as good as a simple and explicit one. Having to write more things is totally worth in the long run
@@spicynoodle7419 there's a lot of SaaS nonesense going around in the JS space but you can actually ignore it and build something independent with next.js too. it's just that nobody is talking about it because there's no sponsorship money in a FOSS project.
For the cloning of readonly one, deep cloning could not be done before. For those that don't understand this concept, because PHP passes all objects (i.e., class instances) around by reference, if when cloning, you don't also clone the underlying object and re-assign on the newly formed object, then it will still be pointing to the old one, which means if that is then mutable and mutated, it will essentially mutate it in all clones. In the example provided, the PHP class is mutable, so if you didn't reassign the internal ->php on clone, but then cloned the Foo object and then modified the php version, like in the 8.3 version, then the original Foo object you cloned from has the same value. Now, with the 8.3 example, modifying the $clonesd->php->version does not modify it for $instance->php->version. In 8.2 this wasn't possible.
I hope that's clear?
"This person must be working on Windows" got me.
Groovy, now all I have to do is make sure that my WordPress clients that I'm unable to manually adjust server settings of due to hosting restrictions that have had their sites working for years don't break due to plugins auto-updating without my knowledge before I get a chance to vet them, or worse - plugins that haven't been updated for a while but are still useful suddenly being considered unusable due to newly deprecated PHP functionality that either I'll have to wait for updates, find alternatives for, or hack in the updates myself.
PHP uses '\' (backspace) as namespace delimiter because '.' (dot) is already used for string concatenation..
I remember this clearly when it got introduced, because that was the drop that filled my bucket and made me abandon PHP. But traits and the new stuff looks damn tempting...
I work with PHP regularly, it's usually a pretty nice experience as long as I'm just building new stuff. Delving into the old stuff is usually painful, but that has more to do with the overall architecture and loads of ugly fixes that you need to keep in mind 10 files away in order to not break shit. That along with an overall reluctance of using classes for loads of things, meaning you have documentation which says "returned array has these keys" but does in fact not have those keys.
The short-term mutability of a deep-cloned, readonly object seems really nice. In JS you'd have to do something like
> const x = { ...data, nested: { ...data.nested, foo: 123 } };
whereas Elixir would have something like
> x = put_in(data, [:nested, :foo], 123)
So this seems pretty similar to the latter. Looks neat.
Python has just added the override feature as well. I think this feature has been overlooked for too long and is mandatory for OOP.
PHP has grown up, but not everyone’s programming skills have kept pace. Let’s give credit where it’s due: PHP's not the problem, it's waiting for some programmers to catch up!
But they still keep hating lmao
PHP hasn't been the problem since v7 i'd say. however, PHP suffers heavily from what i call the PHP-bootstrap-jQuery-syndrome which is when a technology is so accessible that it attracts many inexperienced and untrained developers, resulting in the majority of code written with that technology being very low quality, therefore giving that technology a bad name.
@@FunctionGermany Then AI trains on shit code written by humans, we are doomed.
@@fnfal113 yeah 😔. stupid devs using GPT to write code from 2008 stackoverflow that got 1 upvote (the author).
@@FunctionGermany ouch! I feel attacked but painfully true
@@P8860 don't feel attack. there must be technologies that a lot of junior devs use, otherwise we'd have a lot less software developers today.
pretty much all developers need to write a lot of bad code as a byproduct before they can make anything good.
Bro, PHP namespaces has been around since v5.3 I think, that's like some 15 years ago. Those slashes has meaning in auto loading classes via Composer.
I think your idea of PHP as "garbage" is extremely outdated. Seems to me your idea of PHP is still in the v4 era -- where PHP was ironically king because everything else actually suck.
Now I've no hate for Laravel but even that doesn't represent how really different and good PHP is now. Just plain PHP + PSR + Composer libraries cuts it on its own.
If you really want to use a framework, Symfony is a good choice -- less magical and closer to native PHP.
You have to try modern PHP and you'll see, but don't just go blindly and write in procedural PHP 4 like you used to. At least read on PHP The Right Way and you're good to go.
PHP has come a long way in the last fifteen years.
When laravel does most of the stuffs without causing you pain that react server components is trying to instill.
Deep cloning works great for date classes
5:47 as someone who has written PHP near daily since the ye ol' PHP3 days.. I don't get the deep cloning situation. I can't even think of a scenario where I'd find myself in where that'd be a useful or even desirable thing to do
I'm guessing it's an optimization for things like PSR-7 objects, which are meant to be immutable so every time you mutate one, it hands you back a brand new object with cloned data instead.
finally one video about not hating php
Damn, the chat trying to figure out what a Fully Qualified Name is
I've understood the example for deep cloning magic properties now. Yes the final line on the 8.3 side is outside the magic clone method. But that's not where the fatal error is. The fatal error in 8.2 happens on the last line on the left, where `clone` invokes the Foo::__clone method.
And clone is needed because although Foo is readonly, the PHP class is not readonly, and has a mutable property. So when making a clone of the Foo object we want a deep clone, that has its own instance of PHP, instead of sharing the instance with the original object.
It's a confusing example with an immutable object that contains a reference to a mutable object.
5:51 - That exists since if you have a read-only property on a class (like “Foo” in this case) that you want to clone, you can’t do a _deep clone_ because that property cannot be updated to be cloned as well (hence the “deep” clone of the lower down references). This update fixes that I guess.
PHP + HTMX, you may enjoy it.
7:19 the had a better namespace separator when they first introduced the concept, but then they changed it to a / at the last. I think the separator was ::, which is used to access static members.
The syntax for class virtual functions is absolutely horrific. Objective-C enthusiasts will love it.
they didnt do a major version bump presumably because it is backwards compatible
how could you overlook the new mb_str_pad()
"use php"
I just hate how so many PHP sites have `index.php` at the end of URL. I always thought that it was tacky.
it's "more accurate" and requires less config on the web server.
You can remove that in literal seconds but people just don't bother
i think it's more related to SEO indexes for old websites because people don't want to know how to forward google bots
PHP > JavaScript.
Facts
No.
why are you geh?
Based
typescript though
Prime, you are the best thing that happened to youtube, after youtube itself :)
php is a must for web
You should do Advent of Code in PHP hahaha
I think that has been more than 3 years working with PHP, and it isn't so bad like I did think
This is the reason the only language I like is Go. It don't like when new features are introduced every week. I like having one way of doing things.
PHP always passes objects by reference so cloning an object with a readonly object property will have the cloned object have an readonly object property referencing the same readonly object as the previous one. So by making a clone of the readonly object property in the magic __clone method prevent the side effects of modifying something in the readonly property and making the program go funny (that being the same referenced object in both the original and cloned instance)
feels illegal to be here so soon
Bro, php has match operators and js still don't
3:45 - In PHP, everything is copy-on-write references, if passed "by value". There's no syntax to get a reference, what you can do is force the creation of aliases that act as references [using the =& operator]. You can also declare a parameter as "receiving a reference", which is actually pretty bad, because the user never knows their variable could potentially be used as a output parameter, so it is better avoided.
eg: you can function abc(&$var) { $var = 0; }, when you call it abc($input), input will become 0 even if you never expected it to be a reference pass.
For the clone, readonly props can only be modified inside the constructor. That change makes it possible for you to reinitialize readonly stuff after a clone, if necessary. Not sure I like it, but that's what it is.
Objects are passed by reference. If you care so much why not use simple stdClass object and assign your data to it? 🙂
@@GreyDeathVaccine Objects are not passed by reference. Objects are not passed at all. References to objects are passed by value.
@@GreyDeathVaccine I have no problems with passing stuff by reference, my problem is when you're passing an argument that you don't expect to become magically a reference, say an integer, and the function changes that argument to whatever crazy stuff it wants to change it to. Usually not a problem with std api, but users are crazy.
In PHP you also have 0 visibility over what parameters are going to be by-reference and what parameters are going to be by-value, from the function user side.
Also, since php tends to be copy-on-write everything, there's usually not a whole lot of stuff that you actually want to pass by-reference anyway...
@@barneylaurance1865 Exactly! Assume you have 2 functions:
function a($v) { $v->foo = 0; }
function b(&$v) { $v = 0; }
Then you have a value:
$c = new Something.
if I call a($c), I wouldn't be surprised by something changing inside it, but $c itself is still the reference to that obj. Now if I call b($c), it's a footgun that has just destroyed any hopes that I can debug this shit in less than a day.
$c isn't the reference anymore, $c is something else entirely. It's passing a reference as a reference and the user of the function has NO IDEA that that happened.
Isn't it just arrays that do copy-on-write? I thought the other primitives were just copied directly.
I think they put too much emphasis on being able to deep clone readonly properties with that explanation. I think the bigger deal is being able to modify cloned, readonly properties period, not necessarily for the purpose of deep cloning them. Otherwise the cloned object can never have different values for the readonly properties. I think this is a good stepping stone to further improvements in the future if they add something like `clone with` where you specify which properties of the clone should have new/different values. You can do something similar in Kotlin and Scala 3. It's great for making immutable classes because if everything is immutable, how do you change anything? Well you don't change the object, you clone it with differences. Currently you basically have to duplicate the constructor in a hand rolled cloneWith() method for every single class you make.
Everyone hating on PHP has obviously never built anything with Laravel and they don’t know what they’re missing out on 😔 best developer experience and community I’ve ever experienced.
@ctxz9580you are but a novice - unable to understand beauty & grace
@ctxz9580 you don't understand what you are doing.
Php is getting better. For people already using php, all these improvements are very nice to get. But php will always be worse than a nice, well designed, statically typed, compiled language. Comparing PHPStan or Psalm to a real compiler and the way it reports issues is night and day. Php static analyzers are not part of the language, they are these tacked on things made by the community, and therefore will never be as nice as a compiler that is required and part of the language. Also, php is overly verbose. `readonly`, arrows just to call a method, a dollar sign before every variable. Those might seem like small things, but it all adds up. Compare it to a language like Scala 3 where it is both terse and expressive/readable at the same time.
I like PHP, especially now that Laravel makes it so easy to do stuff.
2:30 : Backslash is the separator for namespaces. Similar to how a "." would be on a Node package name.
3:08 : Not a huge fan of the #[\Override] annotation but It would make maintaining stuff probably a bit easier.
I don't understand why we couldn't just have a PHPDoc @override comment instead. That whay The Language Server could do the same checks. By using an annotation, PHP now has to check this stuff, whenever it loads a script.
There were discussions when it was being added. Iirc they didn't use @ because that's the operator for error message supression
@@ivanjelenic5627 The Problem I see here, is, that it uses the # symbol, which does make it a comment already.
But it is a comment, that is now executed / evaluated at runtime instead of just during writting in the IDE.
With PHPDoc it would be something like /** @overrides [propertyname] */
PHP didn't used to break backwards, which was the problem with the language for a long time. There'd be old stuff they'd mark as "deprecated" but people would still use it.
Now they brokeback... 😏
They try to keep most of the BC breaks for the x.0 major releases, i.e. they're saving up thing to break in 9.0. But there are always a few BC breaks in the x.y releases like this year's.
Honestly, I decided to try Symfony and... it was a text wall just for some basic posting... meanwhile in Django it was like 9 lines. Not worth it.
PHPagen 😀
Hell yeah! I'm not going back tho.
PHP is badass. I have made several applications using PHP and laravel and they are beautiful, fast websites. PHP is awesome but can be slower than JS. If you use a redis DB for sessions and caches, your php laravel site doubles in speed. Using a garbage collector makes it even faster!
maybe the clone method is useful for reflection class? or for testcases?
Im getting a lambo now
Have they fixed the docs yet so you don't have to read comment 15 to find out the function does something random you need to be aware of.
Backward compatibility breaks in minor versions is stupid, they should just follow good old .. version scheme. I like the new features PHP is getting, but they should really wipe out the inconsistency in the language, that would be a great breaking change worth another major version.
some projects have their reasons for not following semver.
maybe regular, smaller breaking changes motivates more teams to update in comparison to major breaking updates which creates demand for supporting the old version or LTS versions.
pho was created before SemVer was popular.
@@marcs9451 that's not true at all. SemVer is a relatively new term but the general procedure is really old.
they only removed some inconsistencies that devs should have stayed away anyway
@@SXsoft99 sure, that may be the case. To avoid having to know such internals, e.g. as an administrator, it is nice to follow the versioning rules. After all, that's the whole point.
Jamaica 🇯🇲 in the building love your videos bro
Ya mon. Welcome
@@redpillsatori3020 huh! Like really bro you bugging 🤣🤣🤣🤣
In my test php swoole was faster then go in typical microservices scenario, surprise
not really most pushing forward release lol not a single example of performance, but in general php8+ going good
I'm still waiting PHP to get rid of str_replace and all legacy shit functions. Also it really needs pseudo-objects when work with scalars
Will the Primagen switch to PHP after this update?
if they remove the dollar sign from variable names i'll look at it
PHP is all about that money.
PHP namespaces resembles the folder structure of the file. Why they use \ \ \, its because you can have 2 functions with same name but different namespace. So you can import both functions but just point to right namespaces. You than need to use as word to rename inports from namespace.. bla bla
the \ is for namespaces
If you have to put a dollar sign before every variable name, you've already lost.
Will you give a chance to C# 12 with .NET 8 and AOT? (F# is still ahead on features)
So __clone is like the init property in C#?
I'd used PHP lots back in 2000, I'd stopped using awk grep, etc. in command line tools! But nah, I'm sorry, not interested. And yes, I still use good'ol bash. Never need awk as much as used to though ... funny that. I suppose data system integrations are better.
You clone the const to a new instance, change its value and then it is locked as the const that it is? You get one free change of value at time of cloning, and then that's it, locked?
1:33 Lmfao
Has he seen PHP's variable variables?
Would you make a review on openswoole on php?
You say you wouldn't hate Laravel, I say you'd like it.
What's next, Perl 6?
I used to hate PHP but I'll be very honest, I'd rather make a new application with PHP 8.3 than with node or even python.
Rogahn Cliff
this looks messier than rust code
Fax
Been trying to learn PHP since PHP 5, now was trying to learn PHP8, now it’s gone to PHP 8.3 before I could get used to PHP8……. The tech is coming out and updates are so fast nowadays how can anyone keep up?!?!?
By sticking to the technologies you chose for a project for as long as it's reasonable to do so, and not changing the minute a new version/framework comes out.
I don't think PHP8 is irrelevant just because 8.3 came out.
@@wolizuka nobody is looking for someone hood in PHP 5, when PHP 8.3 is out…. Same with PHP 8…. As new tech comes out that’s what these jobs want to hire people who have mastered the newest tech
5.6 28-Aug-14
7 3 December 2015
7.1 01 December 2016
7.2 30 November 2017
7.3 6 December 2018
7.4 28 November 2019
8 26 November 2020
8.1 25 November 2021
8.2 8 December 2022
8.3 23 November 2023
how were you not able to keep up? one year is enough to check what's new and refactor the code
@@TheBlackmanIsGod that's just not true? a hefty amount of jobs orbit around maintaining existing code, which is often a few if not several versions behind whatever is the latest thing. As long as there are no security fixes which haven't been backported, there's virtually no reason to update other than improved DX when it comes to established languages.
All of that said, it is quite the exaggeration to say "how can anyone keep up" when few things have been actually added, none of these changes have been paradigm--shifting or anything of the sort and in reality there hasn't been any fundamental changes to the language so if you know PHP 5, you're 95% of the way there to PHP 8
Nonsense. First of all 99% of the language remains the same.
Second of all you don't need to know everything, just know it exists and look it up when you need it.
Would be nice to see you go through Laravel :)
am still use php 7.4
nah, thanks I'll stick with Go.
PHP has always been the best language. Change my mind.
I like how this video started with "I think PHP is trying to become a real language now" and the whole video is "what the hell is this garbage?" 😂
I don't know if it applies to php as well but in c++ you might want to deep copy a const ref if you want to ensure your copy isn't changed by the source since it might be a non const passed as a const. It could also be the you want to store it in a specific location
Ezekiel Pine
I thought it said 3 days ago - but it was 3 minutes ago.
Anyways PHP is the one true superior language.
Sorry just not superior in anything..
If you disagree, name in what it is superior to everything else.
@@martinhotmann7868being bad
@@hitthemill8595 True that ^^
@@martinhotmann7868 superior ecosystem. You can't go wrong with Laravel but if you feel like something different there's also Symfony, that's kinda about it for the majority of devs. You don't have to play catch-up with every other framework trying to reinvent the wheel, or completely changing paradigms between versions
Strike me down with all of your hatred, and your journey towards the dark side will be complete!
i love you prime, youre my goat
Just accept that PHP is better in any way than JavaScript
WEN LARAGEN
Prime's attempts make me wonder how much he makes off of sifting through this crap. Would take a lot to make me do the same.
You need some ice?
Janice Haven
PHP was never backward compatible and that's why it's a pain in the ass to update Laravel projects, which in itself isn't 100% backward compatible either lol.
I don't like PHP and I think it's trash however if I had a project that required the most I would just use it.
When he said the programmer is a windows users because of the above PSR compliant imports, I knew he knows nothing about php.