Developed By Ken Key

Modern PHP in 2026: What Still Works and What to Stop Writing

By Ken Key Nov 21, 2025 5 min read Updated Oct 16, 2026

Modern PHP in 2026: What Still Works and What to Stop Writing
The short answer

In 2026, run PHP 8.4 and start every file with strict types. Keep readonly properties, enums, match expressions, and constructor promotion. Stop writing loose comparisons, untyped properties, and anything below 8.2 on a public server. That's a security problem, not a style choice.

Part of the complete web development guide.

On this page

Most PHP code I get handed to fix was written somewhere between 2012 and 2018, and it shows. Not in a “this is terrible” way. More in a “nobody told the author that half of this is now built into the language” way. So here’s what I actually reach for in 2026, and what I quietly delete when I inherit a codebase.

Start with the version, because it changes everything

PHP 8.4 is the current stable release. 8.1 through 8.3 are still supported, 8.0 hit end of life in late 2023, and 7.4 has been dead for years. If you’re running anything below 8.2 on a public server, that’s a security problem before it’s a performance problem. Upgrading is usually less scary than people think, but the blockers tend to be the same handful of things: old WordPress plugins, a legacy CMS nobody wants to touch, and one weird script from 2016 that everyone is afraid of.

Find out what you’re actually running before you plan anything:

php -v
# or from inside a script
<?php echo PHP_VERSION;

Strict types and typed properties are not optional anymore

Every file I write starts with declare(strict_types=1);. Without it, PHP will happily coerce "5" into 5 and hide bugs that surface six months later in production. With it, you get a fatal error at the point of the mistake instead of a corrupted invoice three layers down.

<?php
declare(strict_types=1);

final class Invoice
{
 public function __construct(
 private readonly int $customerId,
 private readonly float $amount,
 private readonly DateTimeImmutable $issuedAt,
 ) {}

 public function isOverdue(DateTimeImmutable $now): bool
 {
 return $now > $this->issuedAt->modify('+30 days');
 }
}

Constructor property promotion, readonly, and named arguments have been in the language since 8.0 and 8.1. If you’re still writing a constructor that assigns five properties by hand, you’re doing extra typing for no reason.

Stop using mysql_* and start using PDO properly

The old mysql_* functions were removed in PHP 7.0. If you see them in a file, that file has not run in years. The replacement isn’t just mysqli, it’s prepared statements with bound parameters. This is the single biggest thing you can do to close off SQL injection.

<?php
declare(strict_types=1);

$pdo = new PDO(
 'mysql:host=127.0.0.1;dbname=shop;charset=utf8mb4',
 $user,
 $pass,
 [
 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
 PDO::ATTR_EMULATE_PREPARES => false,
 ]
);

$stmt = $pdo->prepare('SELECT id, email FROM customers WHERE status = :status LIMIT :limit');
$stmt->bindValue(':status', 'active', PDO::PARAM_STR);
$stmt->bindValue(':limit', 50, PDO::PARAM_INT);
$stmt->execute();

foreach ($stmt as $row) {
 // ...
}

Two details people miss. ATTR_EMULATE_PREPARES => false makes MySQL do the real prepared statement work instead of PHP faking it. And LIMIT needs PARAM_INT, because binding it as a string will break the query on some drivers.

Password hashing: just use password_hash

I still find MD5 and SHA1 password hashes in databases. Those are not password hashes, they’re checksums, and a modern GPU chews through them in minutes. PHP has had the right answer built in since 5.5.

<?php
$hash = password_hash($plain, PASSWORD_DEFAULT);

if (password_verify($input, $storedHash)) {
 if (password_needs_rehash($storedHash, PASSWORD_DEFAULT)) {
 // upgrade the stored hash on next successful login
 }
}

The password_needs_rehash check matters. It lets you migrate old hashes to the current algorithm gradually, without forcing everyone to reset their password on the same day.

Composer is not optional

If a project has no composer.json, the first thing I do is add one. Not because I want to pull in twenty packages, but because autoloading and a lockfile are how you keep a project from turning into a pile of require_once calls. You can adopt it incrementally. Even a project with zero dependencies benefits from PSR-4 autoloading.

composer init
composer require monolog/monolog guzzlehttp/guzzle
composer dump-autoload -o

Pin your dependencies and commit composer.lock. The lockfile is what makes a deploy reproducible. Skipping it is how you end up with a site that works on your machine and breaks on the server because a minor version changed under you.

Things I’ve stopped doing

  • Writing my own router when nikic/fast-route or a framework already solved it.
  • Using extract() to “simplify” template code. It makes variables appear out of nowhere and breaks every static analysis tool.
  • Suppressing errors with @. Fix the cause, don’t muffle the symptom.
  • Storing config in version control. Use environment variables or a .env file that’s gitignored.
  • Building session handling from scratch. PHP’s session functions are fine and battle-tested.

Where this actually matters for a business

None of this is academic. I’ve rebuilt small business sites on Long Island where the contact form had been silently dropping leads for months because a mail call was wrapped in an error suppressor. I’ve cleaned up booking systems where the database queries were concatenating user input straight into SQL. The fix is rarely a rewrite. It’s usually a week of tightening the parts that touch money, logins, and customer data.

If you’re planning a rebuild rather than a patch job, it helps to work with someone who does this day in and day out. I do custom web development for small businesses and agencies, mostly in PHP and JavaScript, and the upgrade path is usually more straightforward than it looks from the outside.

FAQ

Do I have to move to PHP 8.4 right now?

No, but you should be on 8.2 or higher. Anything below 8.2 is past or near end of life, which means no security patches. 8.4 is worth targeting for new work, and most modern frameworks support it already.

Is it worth fixing old PHP code or should I just rewrite it?

Depends on how much of it is load-bearing. If the code is small and the logic is sound, updating it is faster and cheaper. If it’s tangled with an abandoned framework or a decade of patches, a rewrite often costs less than untangling it. Get a real estimate before deciding.

What’s the one change with the biggest security payoff?

Prepared statements everywhere you touch the database, plus password_hash for anything storing credentials. Those two changes close off the majority of the serious vulnerabilities I find during a review.

Have a project like this?

I do custom web development for Long Island businesses. If you need this done right, let’s talk.