pear2 / Net_RouterOS

This package allows you to read and write information from a RouterOS host using the MikroTik RouterOS API protocol.
http://pear2.php.net/PEAR2_Net_RouterOS
241 stars 116 forks source link

Resolve deprecation notices in modern PHP #76

Closed miken32 closed 2 years ago

miken32 commented 2 years ago

Gets rid of these notices:

PHP Deprecated:  Return type of PEAR2\Net\RouterOS\Message::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/Message.php on line 183
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\Message::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/Message.php on line 193
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\Util::count(?PEAR2\Net\RouterOS\Query $query = null, $from = null) should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/Util.php on line 955
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 311
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 326
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 348
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 364
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::seek($position) should either be compatible with SeekableIterator::seek(int $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 389
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 419
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 407
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 456
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 466
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 374
PHP Deprecated:  Return type of PEAR2\Net\RouterOS\ResponseCollection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in src/PEAR2/Net/RouterOS/ResponseCollection.php on line 297
PHP Deprecated:  stream_get_line(): Passing null to parameter #2 ($length) of type int is deprecated in src/PEAR2/Net/RouterOS/Response.php on line 228

Used the #[\ReturnTypeWillChange] attribute in a few places since mixed is not available as a return type in the (technically) still supported PHP 7.4.

miken32 commented 2 years ago

Note there are still plenty of other notices from other outdated PEAR components. I considered running this code through some modernization cleanups, but not sure how useful it would be given the dated foundation it's built on. Might be an interesting project to rebuild it to use Symfony components...

boenrobot commented 2 years ago

Yeah, I've been thinking about rewriting this lib on top of ReactPHP, perhaps also with some symfony events, as the biggest feature request I've ever gotten is to manipulate multiple routers with one script... which would be far easier with an event loop, and ReactPHP provides that, and has a wide range of PHP versions support.

My only holdup once upon a time was the lack of ability to install those with pear/pyrus, but given pyrus is fully dead, and pear is just up for legacy reasons, I guess I might as well start that, and redirect to it from this project once it's ready.

boenrobot commented 2 years ago

Merged. Thank you. I'll do a release in a few days or so.

miken32 commented 2 years ago

Thanks; I have no experience with React or client/server stuff, but I'd be happy to provide testing, PRs, or bug fixes where I can help. Would be nice to get this old PEAR stuff out of my codebase!