---
title: 'PHP in 2026 is so good..'
source: 'https://youtube.com/watch?v=PLkLhIwVfMk'
video_id: 'PLkLhIwVfMk'
date: 2026-06-15
duration_sec: 0
---

# PHP in 2026 is so good..

> Source: [PHP in 2026 is so good..](https://youtube.com/watch?v=PLkLhIwVfMk)

## Summary

This video demonstrates how to write modern PHP code in 2025, moving from old, unsafe, untyped code to a clean, typed, and robust style. The presenter shows key features like visibility, type declarations, readonly classes, property promotion, and final classes.

### Key Points

- **Old PHP vs Modern PHP** [00:00] — Old PHP was unsafe, untyped, and verbose. The video aims to show how to write modern PHP in 2025.
- **Visibility Modifiers** [00:23] — Replace 'var' with 'private' for properties and add 'public' to functions to make visibility explicit.
- **Type Declarations** [00:34] — PHP is fully typed. Add type hints to properties (string, int) and function return types.
- **Strict Types** [01:14] — Add 'declare(strict_types=1);' to enforce strict type checking, e.g., rejecting a string where an int is expected.
- **Readonly Classes** [01:28] — Use 'readonly' modifier on a class to prevent state mutation. Properties can then be made public, eliminating getters.
- **Property Promotion** [01:57] — Declare visibility and type directly on constructor arguments, removing redundant property assignments.
- **Final Classes** [02:27] — Mark classes as 'final' to prevent inheritance, favoring composition over inheritance.
- **Modern PHP Tooling** [02:52] — PHP has improved tooling: PHPStan (like TypeScript), Pint (linting), and Pest (testing).

### Conclusion

Modern PHP in 2025 is a fully typed, robust language with features like readonly classes, property promotion, and final classes. The presenter encourages viewers to explore further and try PHP at php.new.

## Transcript

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