[0:00] Let's be honest, some of you haven't [0:01] used PHP for 20 years now. And probably [0:03] back in the days, it would look [0:04] something like this. Everything was [0:06] unsafe. Things were untyped, insanely [0:09] verbose. So on this video, I'm going to [0:11] show you how can you move from this into [0:14] PHP in 2025. My name is Noo-Noo and [0:17] welcome to my channel. Just like in C or [0:19] Java, you can also assign visibility to [0:21] properties in functions in PHP. So let's [0:23] start by that and replacing this var [0:25] with something like private. And then [0:27] every time we have a function, let's [0:28] make explicit that this function is [0:29] public by assigning the visibility [0:31] public to this functions. Next, unlike [0:34] you might think, PHP just like [0:35] TypeScript or Rust is also fully typed. [0:38] Meaning that I can go to this properties [0:39] and I can type them. Let's type here [0:41] that this name is a string but also this [0:43] age is an integer. We can do the same [0:45] thing not only on the arguments but also [0:47] on properties. Let's go all the way up [0:49] and say that this name is a string and [0:51] this age is an integer. but also in the [0:53] getters. Every time I get the name, it [0:55] will be a string, but also every time I [0:57] get an age, this will be an integer. So, [1:00] PHP in 2025 is equally fully typed. Hey, [1:03] just a quick pause to say that I have [1:05] this dream of reaching 100K subscribers [1:07] and still be talking about PHP. So, if [1:09] you enjoy this video just a little bit, [1:11] go all the way down, subscribe this [1:12] channel, and like this video. Now, if [1:14] you want to be a little bit more strict [1:15] about types, you can go all the way top [1:17] and add this declare strict types one. [1:19] What this will do is that even if you [1:21] provide a string with a value zero, PHP [1:24] won't accept it because it needs to be [1:26] explicitly an integer value. Now this [1:28] class is the value object. So we don't [1:30] actually plan to change the state [1:32] inside. So what we can do is instruct [1:34] PHP about that and use this readonly [1:36] modifier before the class to instruct [1:38] PHP that the state will never change. [1:41] And in fact, if we try to mutate the [1:43] name or the H, PHP will prevent that [1:45] from happening thanks to the readonly [1:47] keyword. And not that the state can [1:48] change, what we can do is actually make [1:50] these properties fully public because [1:52] they cannot change anyways. Meaning that [1:53] we can go all the way down and also [1:55] remove all these getters. There is a few [1:57] more things we can do to make this code [1:59] a little bit better. One of them is [2:00] called property promotion. So when you [2:02] are providing arguments to a constructor [2:05] and those arguments will be assigned [2:06] directly to properties. What you can do [2:08] is assign those properties directly on [2:10] those arguments. So what I will do here [2:12] is declare the visibility of the name [2:14] directly on the argument and do the same [2:16] thing with the age. And by doing this we [2:18] can effectively remove this code but [2:20] also this code making effectively the [2:22] guest class looking as beautiful as [2:25] this. Now there is one final thing you [2:27] can do to favor composition instead of [2:29] inheritance which is marking classes as [2:32] final especially classes that you want [2:34] to strictly forbid them for being [2:35] inherited. So what you can do is add [2:37] this final keyword meaning that if [2:39] someone were to extend this class, PHP [2:42] will prevent that from happening. Now [2:44] that was just a small example in PHP in [2:46] 20125. There is many things we haven't [2:48] covered today. Things like enums, [2:50] attributes, name it arguments and more. [2:52] If you want to know more about PHP, make [2:54] sure to subscribe my channel because I'm [2:55] literally talking about them every [2:57] single time. Just like any modern [2:59] language, PHP's tooling have also [3:01] massively improved in 2025. We have our [3:04] own TypeScript with PHP stand. We have [3:06] our own linking with pint but also [3:09] testing. We have past PHP. Hope this [3:11] video gives you a different perspective [3:13] how modern PHP is today. If you want to [3:15] start with PHP, go to php.new and is [3:18] literally one command. Hope you enjoyed [3:20] the video and catch you guys next time. [3:26] [Music]