So if I build a class...
class Foo {
public $_string;
public function($sString = 'new string') {
$this->_string = $sString;
}
}
I would like to forcibly say that $sString is of type string in my function arguments, something like this...
class Foo {
public $_string;
public function(string $sString = 'new string') {
$this->_string = $sString;
}
}
but my IDE says "Undefined class 'String'" and php will throw errors, so is there a way to forcibly say what type of variable is being passed into a function in a class or would I have to declare it inside the function like this...
class Foo {
public $_string;
public function($sString = 'new string') {
$this->_string = (string)$sString;
}
}
any help would be appreciated. Thank you.