(DI)为什么我不能在我的PHP代码中执行此操作

i'm trying to understand why i cannot do this in my code ?

<?php
Class Model
{ 
    protected static function insert( Entity $entity )
    {
          # some codes to insert data in the database
    }
}

<?php
Class UserModel extends Model
{ 

    protected static function insert( UserEntity $entity )  
    {
        parent::insert($entity);
    }
}

Basically the UserEntity is also an Entity so why PhpStorm keep telling me "Declaration should be compatible with Model->insert(entity : \Entity)

Even though UserEntity extends Entity when you change the method signature from:

 protected static function insert( Entity $entity )

to:

protected static function insert( UserEntity $entity ) 

Model and UserModel are no longer compatible. What you can do is something like this:

protected static function insert(Entity $entity)
{
    if (!$entity instanceof UserEntity) {
        return \InvalidArgumentException('Entity must be a UserEntity');
    }
    ...
}

Some might argue that breaking the contract by requiring a child object instead of the defined one breaks the interface segregation principle. In any case the methods don't match anymore, because as your method indicates it no longer requires just an Entity and therefore might be incompatible.

edit: There currently is a proposal for what you are trying to do. It is called Parameter Type Widening.