The problem:
I want to run Wordpress 6.x with PHP 8.x in development mode - meaning define('WP_DEBUG', true);
but Wordpress 6.x partial support for PHP 8.x throws a lot of deprecated warnings which do a lot of mess on the screen and also mess with cookies and REST API.
Setting error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
in php.ini
or wp-config.php
does not solve the problem because Wordpress overwrites this setting when you set define('WP_DEBUG', true);
which you want normally have for the development.
The solution is no straight forward and I couldn't find fast, either on Stack or anywhere else so below I will answer my own question and solve the problem for others.