PHP7 type hinting not causing warnings in PHPStorm

Answered

I've created a test class to test type hinting. The code obviously fails, but PHPStorm does not detect the error. I wanted to test if PHPStorm could warn me against these kind of errors. Is this not implemented, a bug, or have I missed a setting?

 

<?php
declare(strict_types=1);

class Test
{

/**
* Test constructor.
* @param int $x
* @return int
*/
public function test(int $x) : int
{
unset($x);
return '';
}

public function test2()
{
return $this->test('');
}


}

$t = new Test();

echo $t->Test();

 

 

1
4 comments

It didn't copy paste well. Ignore the last 2 lines.

I expect a warning for the line: 

return $this->test('');

As it's a string passed into a function that expects an integer.

0

We'll need to doublecheck that, we'll report back shortly.

0

Hi there,

ATM PhpStorm is very forgiving when you passing strings instead of other scalar types -- https://youtrack.jetbrains.com/issue/WI-10904

Other ticket that would be related to your case (in general):

0

Please sign in to leave a comment.