Skip to content

PHPDoc tag @var for constant with type string|null is not subtype of native type string #10911

@gabrielrbarbosa

Description

@gabrielrbarbosa

Bug report

  • Larastan Version: 11.x

larastan/larastan#1928 (comment)

Description

Errors detected in CI

16     PHPDoc tag @var for constant                                
         App\Models\Produto\TestModel::CREATED_AT with type  
         string|null is not subtype of native type string.
           
17     PHPDoc tag @var for constant                                
         App\Models\Produto\TestModel::UPDATED_AT with type  
         string|null is not subtype of native type string. 

Laravel code where the issue was found

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class TestModel extends Model
{
    use HasFactory;

    protected $table = 'test';

    public $timestamps = true;
    const string CREATED_AT = 'data_criacao';
    const string UPDATED_AT = 'data_alteracao';
    
    ...
}

Code snippet that reproduces the problem

https://phpstan.org/r/20335f79-4d10-4cd7-b8a3-8d12b5c1a072

No response

Expected output

I think the expected behavior is that a const string should be valid for "string|null" right?

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions