What are the benefits of forcing a parameter object type when defining a function?

What are the benefits of forcing a parameter object type when defining a function?

for example

Public function setDI (<DiInterface> dependencyInjector)
{
        Let this->_dependencyInjector = dependencyInjector;
}

Public function getDI() - <DiInterface>
{
Return this->_dependencyInjector;
}


Let dependencyInjector = <DiInterface> this->_dependencyInjector;


3.3k
edited Jan '17

Use

        Public function setDI (var dependencyInjector)
        {
                Let this->_dependencyInjector = dependencyInjector;
        }

        Public function getDI()  - >var
        {
                Return this->_dependencyInjector;
        }


        Let dependencyInjector = this->_dependencyInjector;

Whether the effect is the same?



959

Maybe to make sure that function will always get proper parameter type and maybe better compiler optimization of code