Uncaught TypeError: must be an instance of mixed or null, string given
farhadsakhaei opened this issue · comments
Hi,
Bug Description
I set the php version to 7.0
I have a code that used mixed in function parameter argument
But seems that PHP 7.0 doesn't support this
But I didn't get any error for such things
PHP Error LOG:
E_ERROR class-file.php : Uncaught TypeError: Argument 1 passed to __construct() must be an instance of mixed or null, string given
Given the following reproduction Scenario
public static function get_instance( mixed $param = null ) {
and return type:
public static function get_instance( mixed $param = null ) :mixed{
... with this custom ruleset:
<?xml version="1.0"?>
<config name="testVersion" value="7.0-"/>
@farhadsakhaei Please use the bug template as there is now too little information for us to help you.
PHPCompatibility reports on the mixed
type without issue.
@jrfnl
Hi, Thank you for your reply,
mixed type is not compatible with PHP 7.0
And PHPCS doesn't warn for that
@farhadsakhaei Correct, it does not warn, it throws an error.
@jrfnl
It doesn't throw error:
phpcs -p . --standard=PHPCompatibility --runtime-set testVersion 7.0-
..................... 21 / 21 (100%)
Time: 384ms; Memory: 10MB
My code cotains:
function blabla(mixed $param1) {
or
function blabla(): mixed {
And I use PHP 8.3.2, is it matter?
I just need to make my code compatible with PHP 7.0 too
@farhadsakhaei That might depend on the version of PHPCompatibility you are using. Again: use the bug template to provide us with the necessary information.
FOUND 2 ERRORS AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------
3 | ERROR | 'mixed' type declaration is not present in PHP version 7.4 or earlier
| | (PHPCompatibility.FunctionDeclarations.NewParamTypeDeclarations.mixedFound)
3 | ERROR | 'mixed' return type is not present in PHP version 7.4 or earlier
| | (PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.mixedFound)
------------------------------------------------------------------------------------------------------------------------------------------------------
@jrfnl
I was using PHPCompatibility 9.3.5,
I just installed it using composer.
"phpcompatibility/php-compatibility": "*",
is there any another repo to install using composer?
I just uploaded the current github repo and it fixed the problem,
How can I install latest versions using composer?
Thank you
@jrfnl
Thank you for your help
I hope you release version 10 soon