Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Psalm Insane Comparison Laravel Package

orklah/psalm-insane-comparison

Psalm plugin that flags “insane” string-to-number loose comparisons that change behavior in PHP 8 (RFC: Saner string to number comparisons). Helps you find risky == checks like non-empty string vs 0 before upgrading, and suggests safer typing/casts.

View on GitHub
Deep Wiki
Context7

psalm-insane-comparison

A Psalm plugin to detect code susceptible to change behaviour with the introduction of PHP RFC: Saner string to number comparisons

Installation:

$ composer require --dev orklah/psalm-insane-comparison
$ vendor/bin/psalm-plugin enable orklah/psalm-insane-comparison

Usage:

Run your usual Psalm command:

$ vendor/bin/psalm

Explanation:

Before PHP8, comparison between a non-empty-string and the literal int 0 resulted in true. This is no longer the case with the PHP RFC: Saner string to number comparisons.

$a = 'banana';
$b = 0;
if($a == $b){
    echo 'PHP 7 will display this';
}
else{
    echo 'PHP 8 will display this instead';
}

This plugin helps identify those case to check them before migrating.

You can solve this issue in a lot of ways:

  • use strict equality:
$a = 'banana';
$b = 0;
if($a === $b){
    echo 'This is impossible';
}
else{
    echo 'PHP 7 and 8 will both display this';
}
  • use a cast to make both operands the same type:
$a = 'banana';
$b = 0;
if((int)$a == $b){
    echo 'PHP 7 and 8 will both display this';
}
else{
    echo 'This is impossible';
}
$a = 'banana';
$b = 0;
if($a == (string)$b){
    echo 'This is impossible';
}
else{
    echo 'PHP 7 and 8 will both display this';
}
  • Make psalm understand you're working with positive-ints when the int operand is not a literal:
$a = 'banana';
/** @var positive-int $b */
if($a == $b){
    echo 'This is impossible';
}
else{
    echo 'PHP 7 and 8 will both display this';
}
  • Make psalm understand you're working with numeric-strings when the string operand is not a literal:
/** @var numeric-string $a */
$b = 0;
if($a == $b){
    echo 'PHP 7 and 8 will both display this depending on the value of $a';
}
else{
    echo 'PHP 7 and 8 will both display this depending on the value of $a';
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony