RubixML / Tensor

A library and extension that provides objects for scientific computing in PHP.
https://rubixml.com
MIT License
232 stars 28 forks source link

Warnings when using Tensor on PHP 8.1 #28

Closed mlocati closed 2 years ago

mlocati commented 2 years ago

When using the tensor PHP extension with PHP 8.1 we have these PHP warnings:


Deprecated: Return type of Tensor\Vector::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in Unknown on line 0

Deprecated: Return type of Tensor\Vector::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in Unknown on line 0

Deprecated: Return type of Tensor\Matrix::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in Unknown on line 0

a simple fix is to simply add this line right before these methods:

#[\ReturnTypeWillChange]

See https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.core.type-compatibility-internal

andrewdalpino commented 2 years ago

I saw these warnings too @mlocati but didn't look into how to fix them. Thank you for the info it's greatly appreciated!