How to Fix PHP Strict Types Declaration, Suppress Deprecation Warnings, and Avoid XAMPP + MySQL Issues 🔧

When working with PHP, especially on projects involving tools like phpMyAdmin or Twig, you might face these common issues:
1️⃣ Correct Placement of declare(strict_types=1);
The
strict_types
declaration must be the very first statement in your PHP file right after the<?php
tag.Placing any code, including
error_reporting()
or whitespace, before it will cause a fatal error:"strict_types declaration must be the very first statement in the script."
How to fix:
<?php declare(strict_types=1); // Your other code follows...
2️⃣ Suppressing PHP 8.1+ Deprecation Warnings
PHP 8.1 introduced many deprecation notices (e.g.,
realpath(null)
, Twig’scount()
warnings) which don’t break your app but clutter your logs.To suppress these notices during development, configure error reporting like this:
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); ini_set('display_errors', 0);
FIle Open: C:\xampp\phpMyAdmin\index.php
Add this code top and save.
<?php declare(strict_types=1); error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED); ini_set('display_errors', 0); use PhpMyAdmin\Routing; if (! defined('ROOT_PATH')) { // phpcs:disable PSR1.Files.SideEffects define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); // phpcs:enable } global $route, $containerBuilder; require_once ROOT_PATH . 'libraries/common.inc.php'; $dispatcher = Routing::getDispatcher(); Routing::callControllerForRoute($route, $dispatcher, $containerBuilder);
Subscribe to my newsletter
Read articles from Sharif Uddin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
