Larastan: preg_match expects string, int given

Created on 2 Aug 2018  Â·  7Comments  Â·  Source: nunomaduro/larastan

  • Larastan Version: 0.2.4
  • --level used:5

Description:

Parameter #2 $subject of function preg_match expects string, int given.

Laravel code where the issue was found:

$gap = 92568 - 94980;

preg_match("/([-+]{0,1})([0-9]{1,})/", $gap, $matches);
question

All 7 comments

The behaviour seems correct.

On Thu, 2 Aug 2018 at 10:56, ForzaSFerrari notifications@github.com wrote:

>

  • Larastan Version: 0.2.4
  • --level used:5

Description:

Parameter #2 $subject of function preg_match expects string, int given.

Laravel code where the issue was found:

$gap = 92568 - 94980;preg_match("/([-+]{0,1})([0-9]{1,})/", $gap, $matches);

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/nunomaduro/larastan/issues/109, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGZuHe3PTpcAWSth7jCWJ7v1yib2gfdks5uMr6ogaJpZM4Vr5CO
.

>

Ondřej Mirtes

I think so too, because if I would add an (int) within the preg_match for $gap. I would get the following result. Casting to int something that's already int and in phpstand himself there is no error at this point.

The argument is supposed to be string, not int, so PHPStan is right here.

On Thu, 2 Aug 2018 at 11:51, ForzaSFerrari notifications@github.com wrote:

I think so too, because if I would add an (int) within the preg_match for
$gap. I would get the following result. Casting to int something that's
already int and in phpstand himself there is no error at this point.

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/nunomaduro/larastan/issues/109#issuecomment-409871830,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGZuMLs-Pw5v83bKtCOI9uEZkxD5sa3ks5uMsuWgaJpZM4Vr5CO
.

>

Ondřej Mirtes

@ForzaSFerrari PHPStan is right here.

@ForzaSFerrari

@ForzaSFerrari Please try:

$gap = 92568 - 94980;

$gap = (string) $gap;

preg_match("/([-+]{0,1})([0-9]{1,})/", $gap, $matches);

Thanks, for this example. It's been fixed.

Was this page helpful?
0 / 5 - 0 ratings