What to Expect from PHP 8.5: Upcoming Features and Their Uses

PHP 8.5, scheduled for release on November 20, 2025, continues the evolution of the PHP language with a mix of new features, enhancements, and deprecations aimed at improving developer productivity, runtime performance, and language consistency.

Let’s take a quick look at the most anticipated features in PHP 8.5 and their practical applications.

🔧 1. Static Closures in Constant Expressions
What it is:
You’ll be able to embed static closures (anonymous functions) inside constant expressions, such as class constants or attribute arguments.

Use case:
This allows powerful, reusable logic in metadata, especially for frameworks and libraries relying on attributes or constant configurations.

const TRANSFORM = fn($x) => $x * 2;

📚 2. Improved Fatal Error Stack Traces
What it is:
When ini_set(‘fatal_error_backtrace’, 1) is enabled, full stack traces will now be available even for fatal errors.

Use case:
This is a major boost for debugging in production or CI environments, allowing faster root cause analysis of fatal issues like type errors or uncaught exceptions.

🧹 3. Deprecations and Cleanups
The Directory class constructor will be removed in favor of the dir() helper function.

MHASH constants (like MHASH_MD5, MHASH_SHA1) will be removed as part of crypto library cleanup.

Use case:
These removals encourage developers to use modern and secure APIs, like hash() or hash_hmac().

🧪 4. New Array Helpers: array_first() and array_last()
What it is:
These functions return the first or last element of an array, optionally based on a callback.

array_first($array, fn($item) => $item > 10);
array_last($array, fn($item) => $item < 5);

Use case:
Improves code readability when searching for specific elements at array boundaries—ideal for filtering, pagination, or traversal logic.

📦 5. Internationalization Helpers
What it is:
locale_is_right_to_left() and Locale::isRightToLeft() help determine text direction.

Use case:
Supports multilingual applications where layout direction (RTL vs. LTR) must dynamically adjust based on locale (e.g., Arabic, Hebrew).

🛠 6. New CLI Option: –ini=diff
What it is:
The php –ini=diff command shows the difference between loaded and default php.ini values.

Use case:
Great for debugging configuration mismatches, especially across environments or Docker containers.

Adding user authentication for Lorem-Framework

Users Table

For this tutorial, we need to setup our Users table first. Create the table by running this SQL query in your PHPMyAdmin page:

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(25) NOT NULL,
  `password` char(32) NOT NULL,
  PRIMARY KEY (`id`)
);

We have our Users table ready, let’s add a dummy record there. Insert a new record by following the instructions here.

Login Page

What we need now is our login page. Create a new page called login and save it in your pages folder as login.php and add the following codes:

<form method="post">
	<input type="hidden" name="action" value="login_user">
	<input type="text" name="username" placeholder="Username"><br>
	<input type="password" name="password"><br>
	<input type="submit" value="Login Now">
</form>

In the code snippet above, you’ll notice that we have a hidden field with a name action and the value is login_user. This means that when we click “Login Now”, the action “login_user.php” in the actions folder gets executed.

Login Action

After the user submits the form, we need to make sure that we catch all the information they sent. Since we used the post method in our form, we will use $_POST to handle the login details and check if the user exists. Add the following codes in your login_user.php:

<?php 
	if( isset( $_POST[ 'username' ] ) && isset( $_POST[ 'password' ] ) ) {
		$username = $_POST[ 'username' ];
		$password = md5( $_POST[ 'password' ] );
		$result = $DB->query( "SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1" );
		if( $result && $result->num_rows > 0 ) {
			$user = $result->fetch_object();
			$_SESSION[ 'userid' ] = $user->id;
			$_SESSION[ 'username' ] = $user->username;
			echo "Welcome back " . $_SESSION[ 'username' ] . "!";
		}
	} else {
		echo "Please fill all the fields.";
	}
?>

Explanation:

Line #2: Checks if the username and password field have been filled-in.

Line #4: We encrypt the password to match our encrypted password in the database.

Line #5: We check in the database if the username and password exists in our Users table.

Line #6: We check if the query returns a record.

Line #8 and #9: We use $_SESSION to remember the user details. You can read more about sessions here. Please take note that sessions are automatically started in Lorem-Framework.

Now we have a basic Login feature in our site, you can further improve it and make more experiment to fully understand.

Using MySQL multi query and creating a counter variable in PHP

cntI had this problem where I need to change the order of the products we have and  update them from the most popular to least popular. So what I did, I declared a variable that will act as a counter and set the column order_num to the current value of the counter. Here’s what I did:

$db = new mysqli("server", "user", "pass", "db_name");

$query = "set @cnt := 0;";

$query .= "update tbl set order_num = (@cnt := @cnt + 1);";

$db->multi_query($query);

You can also order specific record by adding an IN clause like:

$query .= "update tbl set order_num = (@cnt := @cnt + 1) where id IN (23, 76, 9, 45) order by field(id, 23, 76, 9, 45);";

Adding PHP Mobile Detect in CakePHP1.3 as a component

cake-logoIt seems that the library is not available for old version of CakePHP specifically in 1.3 only in 2.x. So what I did I converted the library as a component, there’s is nothing special about the conversion actually only if you are new to the Framework. Just download the file and unzip it, put it in your /app/controller/components directory.

Download >> Mobile Detect

How to use it:

In one of your controllers, append it in your $components variable like:

Class MyPageController extends AppController
{
  public $components = array('MobileDetect'); // adding the libraby in to your components

  public function beforeFilter() {
    parent::beforeFilter();
  }

  public function beforeRender() {
    // check the user's device and render the proper layout
    if($this->MobileDetect->isTablet()) {
      $this->layout = 'tablets';
    } elseif($this->MobileDetect->isMobile()) {
      $this->layout = 'mobiles';
    } else {
      $this->layout = 'default';
    }
  }
}

To download the original file go here.