Out of curiosity, and for using it a lot without knowing it right, if necessary, setting the variable type is something I do in 100% of my code.
It is usually defined by something like this:
class classe
{
private $dado;
public function dado(int $dado = 1)
{
$this->dado = (int) $dado;
return $this;
}
}
Or in rare cases where there is no object orientation:
$var = (int) 1;
The question is:
Define types in 100% of code reduces or improves performance? (same that the gain or loss of performance is negligible)
And a second question is:
Is it worth validating the type?
Example:
class classe
{
private $dado;
public function dado(int $dado = 1)
{
if(is_int($dado) == true)
{
$this->dado = (int) $dado;
}else
{
$this->dado = die('Tipo não suportado');
}
return $this;
}
}
PS: In the example in question I'm trying to improve performance this is an abstraction layer for building pages with CSS Bootstrap 4 + JS.