Trends and changes in PHP that skilled developers should know

There are continuous changes and novelties in tech, so staying informed goes a long way for developers and companies. The PHP development landscape shows significant advancements that shift how developers build and maintain apps. But, PHP developers need to be aware of the current and emerging trends and embrace them to stay competitive and provide the utmost quality development solutions.

We discussed noteworthy changes and trends in PHP with Arman Poghosyan, a Senior Fullstack Software Engineer at Proxify, and he gave us some valuable insights worth sharing.

Let's begin.

Exciting new things are expected with PHP. Let's see the potential each of them holds.

  • New PHP version 8.3 – The v 8.0 ends with 2023, but if someone upgrades to 8.3, this can be slightly difficult overall. However, this new release already announces randomizer add-ons, json_validate, and improved unserialize() error handling.

  • Responsive web design in PHP development – With more popularity of responsive web design, more user-friendly interfaces are needed to cater to various devices and users. PHP developers use HTML and CSS to develop websites to automatically adapt to any environment for an optimized user experience across mobile phones, tablets, and desktops.

  • Fortified website security – With the alarming rise of global cyberattacks, PHP developers focus on robust cybersecurity. PHP frameworks, for example, Phalcon and CodeIgniter, offer caching, encryption, and asset management features.

  • Harnessing Java and PHP in web development – Combining Java and PHP frameworks is a powerful combo. Java offers top-notch security, and PHP offers exceptional speed. So, when companies adopt both these, they reduce costs and rapidly upgrade apps.

  • Emergence of new PHP communities – These new communities will grow fast, such as the phpc.social, currently with a total of 83 financial supporters so far and thousands of active users.

  • A PHP developer shortage will continue – Interestingly enough, among the trends or things to expect is the demand for PHP developers. And also, not surprisingly, in 2023 and beyond, getting a hold of great PHP developers could still be a bit challenging.

Boost your team

Proxify developers are a powerful extension of your team, consistently delivering expert solutions. With a proven track record across 500+ industries, our specialists integrate seamlessly into your projects, helping you fast-track your roadmap and drive lasting success.

Find a developer

The state of PHP – features, changes, and future updates

PHP remains a popular choice among developers and safely keeps up with dozens of other popular languages, as shown on Stack Overflow’s Developer Survey.

Its popularity is tied closely to the demand, but also to big tech giants such as Lyft, Facebook, and Slack (among many) relying on it, making it even more popular. It is an excellent addition to CMSs such as Drupal and WordPress, and it has a robust framework such as Laravel, so it is an all-around helpful asset for developers and businesses.

PHP's latest released version 8.2 was in November 2022 that brought some interesting and useful features, tools, and upgrades that are still relevant in 2023 and beyond. Some include readonly classes, deprecated dynamic properties, null, true, and false as stand-alone types, and other performance updates.

Let's break these down.

1. Readonly classes

PHP 8.1 introduced the readonly properties, making marking properties as readonly very easy. A new RFC (Request for Comments), such as this one, offers an upgrade to the existing feature by introducing a practical, convenient way for property declaring (of all properties) in a class that is readonly in a single syntax.

  • How it was before:
class Post
{
public function __construct(
public readonly string $title,
public readonly Author $author,
public readonly string $body,
public readonly DateTime $publishedAt,
) {}
}
  • How it is now:
readonly class Post
{
public function __construct(
public string $title,
public Author $author,
public string $body,
public DateTime $publishedAt,
){}
}

Regarding functionality, when a class is readonly, it equals every class being readonly. Still, when it's prevented to add dynamic properties to a class, the benefit is as shown below:

$post = new Post(/* … */);
$post->unknown = 'wrong';
Uncaught Error: Cannot create dynamic property Post::$unknown

In this case, it's crucial to ensure that the parent and child classes are marked as readonly – this applies if you intend to extend a readonly class.

2. Deprecated dynamic properties

This change still belongs on the list of improvements and upgrades but has some potential downsides worth considering. Starting from PHP 8.2, the dynamic properties are deprecated, resulting in ErrorException being thrown in PHP 9.0.

class Post
{
public string $title;
}
// …
$post->name = 'Name';

An important thing to note here is that all those classes that use the two Magic Methods of PHP will still function as usual, despite introducing readonly properties. Those methods are:

1) get 2) set

class Post
{
private array $properties = [];
public function __set(string $name, mixed $value): void
{
$this->properties[$name] = $value;
}
}
// …
$post->name = 'Name';

3. New random extension

In PHP 8.2, we've seen a newly introduced random number generator, and it is addressing different issues from the previous implementation. That new generator has a much improved performance, enhanced security, simpler maintenance, and removes any global state problems. It also removes hard-to-detect bugs linked to random PHP functions.

Also, a new class is introduced, the Randomizer, which allows flexible switching between different randomizer engines, all based on specific requirements. Such requirements include a clear distinction between production and testing environments.

$rng = $is_production
? new Random\Engine\Secure()
: new Random\Engine\Mt19937(1234);

$randomizer = new Random\Randomizer($rng);
$randomizer->shuffleString('foobar');

4. null, true, and false as standalone types

With the latest PHP versions, there are three new standalone types, null, true, and false.

Speaking of type safety, it is worth sharing that all of these types have their significance. One normal scenario is the built-in functions of PHP, and the false type is used as a return type, but only when an error occurs.

The file_get_contents is an example of this:

file_get_contents(/* … */): string|false

Before PHP v. 8.2, there was the possibility of using false type and other types as a union. But, with v 8.2, the false type can be used as a standalone type on its own:

function alwaysFalse(): false
{
return false;
}

And the same applies to true and null.

5. Disjunctive Normal Form types (DNF)

With the introduction of the DNF, a combination of union and intersection types is allowed, but with one specific rule to follow. That rule says when we combine union and intersection types, the intersection has to be enclosed in brackets, as in the syntax example below:

function generateSlug((HasTitle&HasId)|null $post)
{
if ($post === null) {
return '';
}
return
strtolower($post->getTitle())
. $post->getId();
}

In this class, the DNF type is:

(HasTitle&HasId)|null 

This DNF type addition is beneficial because it allows for nullable intersection types, considered a significant use case for this specific feature. It offers better flexibility for handling types, mainly when we deal with particular scenarios, such as a type being an intersection of multiple types or null.

6. Constants in traits

This feature allows us to use the constraints within the traits as such:

trait Foo
{
public const CONSTANT = 1;
public function bar(): int
{
return self::CONSTANT;
}
}

If we want to access the defined constant within a trait, we cannot do it by using the trait's name, not from outside or within the trait.

trait Foo
{
public const CONSTANT = 1;
public function bar(): int
{
return Foo::CONSTANT;
}
}
Foo::CONSTANT;

If we have a defined constant within a marked public trait, we can access this through the class that utilizes that trait. But, we cannot access it directly via the trait:

class MyClass
{
use Foo;
}
MyClass::CONSTANT; // 1

7. Redact parameters in backtraces

It is a widespread practice in codebases to forward the production errors straight to a service responsible for monitoring and notifying developers about specific issues. This process entails the transmission of stack traces to a third-party service. Still, these stack traces could contain sensitive data, such as passwords, environment variables, and usernames.

With PHP v. 8.2., the indication of sensitive parameters is simpler through an attribute, and developers don't need to worry about having these appear in stack traces during errors.

The example below is from RFC (Request for Comments), showcasing the functionality:

function login(
string $user,
#[\SensitiveParameter] string $password
) {
// …
throw new Exception('Error');
}
login('root', 'root');

For example, those coding in the old PHP version might overlook a particular problem with an error showing up. The error that occurs will look as shown below, but only the new PHP version will notify that an error occurred:

Fatal error: Uncaught Exception: Error in login.php:8 
Stack trace: 
#0 login.php(11): login('root', Object(SensitiveParameterValue))
 #1 {main} thrown in login.php on line 8

8. Fetch properties of enums in const expressions

This change in PHP allows us to use -> or ?-> for easier access to enum properties in constant expressions. This change was introduced to enable easy retrieval of the enum's name and value properties when the enum objects have no permissions (for example, within array keys).

The result of this is in the code shown below, where it's clear how this new behavior would be valid now:

enum A: string
{
case B = 'B';
const C = [self::B->value => self::B];
}

9. Return type changes for DateTime::createFromImmutable() and DateTimeImmutable::createFromMutable()

  • These methods used to look like:
DateTime::createFromImmutable(): DateTime
DateTimeImmutable::createFromMutable(): DateTimeImmutable
  • But with the new version of PHP, they changed to:
DateTime::createFromImmutable(): static
DateTimeImmutable::createFromMutable(): static

Such a change is beneficial and logical because it enhances the capabilities for static analysis for the classes extending from DateTime and DateTimeImmutable. Such a modification like this one is considered a “breaking change” and might impact the custom implementation extending from these two classes above.

10. utf8_encode() and utf8_decode() deprecations

With v. 8.2., if we use utf8_encode() or utf8_decode(), we could trigger specific deprecation notices, as shown:

Deprecated: Function utf8_encode() is deprecated Deprecated: Function utf8_decode() is deprecated

These two functions are misleadingly named, thus, they create confusion. Such functions can convert between ISO-8859-1 and UTF-8, even despite the names suggesting a broader functionality. RFC provides a much better explanation for this rationale. But, as an alternative option, RFC proposes using mb_convert_encoding() instead.

11. Locale-insensitive strtolower() and strtoupper()

The locale doesn't affect strtolower() and strtoupper() functions, but they also no longer provide the locale-sensitive case conversion. To succeed at the localized case conversion, utilize the function mb_strtolower().

12. Signature changes to SPL (Standard PHP Library) methods

If you want to make sure that all the correct and suitable type signatures are enforced and used, there were some modifications done to several methods of the SPL classes:

SplFileInfo::_bad_state_ex()
SplFileObject::getCsvControl()
SplFileObject::fflush()
SplFileObject::ftell()
SplFileObject::fgetc()
SplFileObject::fpassthru()
SplFileObject::hasChildren()
SplFileObject::getChildren()

13. New "n" modifier in PCRE library

The n modifier usage (NO_AUTO_CAPTURE) is now permitted in the **pcre*** functions.

14. ODBC username and password escaping

The ODBC is an extension upgraded to the newest PHP version. The update was made to escape the username and password only when the connection string and the username/password are provided, but they must also be appended. This same behavior applies to PDO_ODBC too.

15. Deprecate ${} string interpolation

With PHP, we have many methods that can be used to incorporate variables into strings. But, such an RFC proposes deprecation of two less common approaches because they confuse and are rarely used:

"Hello ${world}"; Deprecated: Using ${} in strings is deprecated "Hello ${(world)}"; Deprecated: Using ${} (variable variables) in strings is deprecated

For clarification, the two most widely used string interpolation methods are still functional:

"Hello {$world}";
"Hello $world";

16. Deprecate partially supported callables RFC

These callables may be invoked with call_user_func($callable) but never through a direct calling of $callable(). But we have to always keep in mind that the amount of callables in this category is limited:

"self::method"
"parent::method"
"static::method"
["self", "method"]
["parent", "method"]
["static", "method"]
["Foo", "Bar::method"]
[new Foo, "Bar::method"]

This change makes progress toward a better enabling of callable for typed properties. In this case, all callables rely on context and are not randomized. For example, “self::method” refers to a specific method, which will vary by the class where a call or callability check has already been made. Mostly, this same context dependence will apply to the utilized form of “new Foo, “parent::method”.

There is another objective to this RFC respectively; reducing dependency on the context for callables. When we implement this RFC, scope dependence remains limited to method visibility. For example, “Foo::bar” can be visible in one scope but might not be visible in another.

In the future, if callables are restricted to public methods (with private methods requiring first-class callables or even Closure::fromCallable() for scope independence), then the callable type will be well-defined, and we can employ it as a property type. Still, remember that this RFC does not propose changes to visibility handling.

What is still lacking in PHP that should be added or improved?

There are still some things that need to be improved with PHP. For example, Arman adds what he would like to see upgraded in the future:

“PHP would have better usability if there were more debugging tools, such as the accessible resources of Ruby or Java. Additionally, more ORDBMS (object-relational database management systems) would prevent slowness and memory consumption in PHP apps.”

Further, PHP still needs to be ideal for large-scale apps, and could lead to difficult code interpretation, especially when someone unfamiliar with the language wrote the code.

And lastly, PHP should be more easily portable between different operating systems. Otherwise, there are notable compatibility issues during code deployment on diverse server environments.

Developers will have an easy time programming with PHP if they are skilled and , knowledgeable, and use all PHP trends and changes in practice.

Another motivator is that developers that always know the latest trends in this language will be valuable team members to any business building in PHP because they won't rely on outdated development methods and instead focus on trending novelties.

Below are the PHP tools and features that make a developer's job more accessible and valuable.

Going further, these additional improvements and upgrades will be crucial to add to the current PHP knowledge and expertise:

  • Extensive library access – PHP has a vast standard library offering superb modules and built-in functions. These built-in functions (and modules) make it easy for developers to work on most tasks without significant and tedious efforts. This will help manipulate strings, handle file operations, or even do database work.

  • Notable simplicity of usage – PHP is known for being simple to use. Its syntax is straightforward to learn, so developers of various levels can work with it, quickly write code and build web apps.

  • A rich framework ecosystem – PHP frameworks such as Laravel, CodeIgniter, and Symfony are significant assets for building web apps. Again, we have many incredible built-in features such as database abstraction, form validation, routing, and security, all cutting development time significantly. With this, the developer may also reuse code and scale apps much easier.

  • AI in PHP programmingWith PHP, developers can easily integrate AI through many frameworks and libraries. Certain preferred libraries of PHP are Rubix ML and PHP-ML, and they offer many algorithms (e.g., decision trees, clustering, and neural networks). Such algorithms are best used for the development of intelligent apps. On the other hand, the frameworks of PHP, such as Symfony and Laravel, offer extensions and various tools for smooth working with AI libraries. This also helps majorly with the integration of AI features in web apps.

  • Cross-platform compatibility – It is great to know that PHP efficiently runs on more operating systems, including macOS, Windows, and Linux. This means developers can efficiently work in different environments without reinventing the code. PHP apps are easily deployed on many hosting platforms.

  • Integration capabilities – Integration with web servers, various databases, and technologies has never been easier than now. PHP has robust support for databases such as SQLite, PostgreSQL, and MySQL for easy data manipulation. With protocols such as HTTP, PHP easily communicates with web servers and interacts with other services through APIs.

  • Active and large community – In the developer communities, the PHP developers can get support and assistance for their work and will have better access to anything new in development. These communities constantly discuss online forums, tutorials, documentation, user-contributed libraries, and more worth knowing.

It is not just important to mention changes and trends in PHP to keep an eye on. To be a good PHP developer, there must be a desire to learn and upskill. Logically, without the willingness to learn, the PHP developer won't upskill or introduce PHP novelties into your business.

“There are several consequences to a business this way. Building and maintaining web apps becomes difficult. Engagement deadlines will suffer, just as the scaling of apps will. Also, updates won't be conducted on time, and compatibility will be faulty between browsers and software versions.”

Lack of expertise and no desire to upskill in PHP will also create more issues down the road.

“All of this results in poor code quality, decreased performance of websites, apps, and security vulnerabilities. Businesses will not easily access solutions of PHP communities or implement the best strategies out there too.”

Final thoughts

Finding great PHP developers can be easy if you know where to look. Most importantly, you'll recognize skilled developers' proactive attitude and desire to stay informed, learn, and use the latest PHP trends and changes. And only those eager to upskill their knowledge can help any business thrive in the highly competitive IT industry.

Arman Poghosyan

Arman Poghosyan

Senior Fullstack Software Engineer

11 years of experience

Expert in PHP

Arman is a seasoned Web Developer with over eight years of experience, specializing in PHP development. He pairs his deep technical expertise with a solid background in quality assurance, ensuring that every project meets the highest standards of functionality and performance. Known for his leadership skills and ability to manage complex projects, Arman has consistently played a key role in all phases of development, delivering reliable and efficient solutions that drive success.

Verified author

We work exclusively with top-tier professionals.
Our writers and reviewers are carefully vetted industry experts from the Proxify network who ensure every piece of content is precise, relevant, and rooted in deep expertise.

Arman Poghosyan

Arman Poghosyan

Senior Fullstack Software Engineer

11 years of experience

Expert in PHP

Arman is a seasoned Web Developer with over eight years of experience, specializing in PHP development. He pairs his deep technical expertise with a solid background in quality assurance, ensuring that every project meets the highest standards of functionality and performance. Known for his leadership skills and ability to manage complex projects, Arman has consistently played a key role in all phases of development, delivering reliable and efficient solutions that drive success.

Verified author

We work exclusively with top-tier professionals.
Our writers and reviewers are carefully vetted industry experts from the Proxify network who ensure every piece of content is precise, relevant, and rooted in deep expertise.

Find your next developer within days, not months

In a short 25-minute call, we would like to:

  • Understand your development needs
  • Explain our process to match you with qualified, vetted developers from our network
  • You are presented the right candidates 2 days in average after we talk

Not sure where to start? Let’s have a chat