PHP code example of kayw-geek / phpstan-type-trace

1. Go to this page and download the library: Download kayw-geek/phpstan-type-trace library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kayw-geek / phpstan-type-trace example snippets


function compute(?float $discount = null): float
{
    $discount ??= 0.1;
    traceType($discount, 'after ??=');
    return 1 - $discount;
}

function traceType(mixed $value, ?string $reason = null): void
bash
./vendor/bin/phpstan-trace inspect src/Foo.php:42 myVar

 ------ -----------------------------------------------------------
  Line   PriceCalculator.php
 ------ -----------------------------------------------------------
  5      Type chain for $discount in compute — after ??=
           L3   param      float|null
           L4   assign-op  float
 ------ -----------------------------------------------------------