Skip to content

Binary operations on non-empty-string and string gives different results #6624

@canvural

Description

@canvural

Bug report

Hi,

Binary operations between string and int, gives errors as expected. Except dividing!

But the same operations between non-empty-string and int does not produce any error.

In runtime these all error.

Code snippet that reproduces the problem

https://phpstan.org/r/980008ff-df01-4485-aab0-1fd7b8a73f55

<?php declare(strict_types = 1);

/** @var non-empty-string $foo */
/** @var string $bar */

echo ($foo + 10); // Should error
echo ($foo - 10); // Should error
echo ($foo * 10); // Should error
echo ($foo / 10); // Should error

echo ($bar + 10); // Gives error correctly
echo ($bar - 10); // Gives error correctly
echo ($bar * 10); // Gives error correctly
echo ($bar / 10); // Should error

Expected output

Error is expected for the operations on $foo

Did PHPStan help you today? Did it make you happy in any way?

Yes!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions