I'm implementing an Iterator interface and if I implement it returning scalar (following the reference http://php.net/manual/en/class.iterator.php), I got this error:
TypeError: Return value of Collection::key() must be an instance of scalar, integer returned
The class implementation:
class Collection implements \Iterator
{
public function key(): \scalar
{
return key($this->colecao);
}
// other methods implementations...
}
According to the PHP reference, integer should be considered a scalar value (http://php.net/manual/en/migration70.new-features.php):
Scalar type declarations come in two flavours: coercive (default) and strict. The following types for parameters can now be enforced (either coercively or strictly): strings (string), integers (int), floating-point numbers (float), and booleans (bool).
Is there some mistake in my code your would it be a bug?
Thank you for any explanation!
PHP does not have a type known as \scalar
. PHP only supports those types. And your \scalar
type looks like it is another class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With