gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 280 forks source link

Deprecation warnings in PHP 8.1 #871

Closed ipsod closed 2 years ago

ipsod commented 3 years ago

I'm using redbean 5.7 and PHP 8.1.0RC2 with error_reporting(E_ALL). I don't know if this is an issue - it happens upon require('rb.php');.

Deprecated: Return type of RedBeanPHP\OODBBean::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/php/rb.php on line 2062

Deprecated: Return type of RedBeanPHP\OODBBean::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 /var/www/html/php/rb.php on line 3072

Deprecated: Return type of & RedBeanPHP\OODBBean::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 /var/www/html/php/rb.php on line 3108

Deprecated: Return type of RedBeanPHP\OODBBean::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 /var/www/html/php/rb.php on line 3055

Deprecated: Return type of RedBeanPHP\OODBBean::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 /var/www/html/php/rb.php on line 3090

Deprecated: Return type of RedBeanPHP\OODBBean::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/php/rb.php on line 3248

Deprecated: Return type of RedBeanPHP\OODBBean::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/php/rb.php on line 3855

gabordemooij commented 3 years ago

Thanks will look into this

gabordemooij commented 3 years ago

This should fix it...

https://github.com/gabordemooij/redbean/commit/bce185b270ef8ddc733ce803a4067f09e2788e23

gabordemooij commented 3 years ago

Can you confirm this works correctly?

gabordemooij commented 3 years ago

@ipsod Can you confirm this works correctly please?

ipsod commented 3 years ago

I'd be happy to, but I don't know how and don't have the time to research how to at the moment.

I'm currently using RedBean by including the single file downloaded from the website. If you can provide concise directions, I can test on my machine.

gabordemooij commented 3 years ago

https://redbeanphp.com/downloads/RedBeanPHP5_7_1RC1.tar.gz

gabordemooij commented 3 years ago

@ipsod I created a single file for you for testing

ipsod commented 3 years ago

It's still giving these errors:


Deprecated: Return type of RedBeanPHP\OODBBean::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/php/rb_new.php on line 2063

Deprecated: Return type of RedBeanPHP\OODBBean::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 /var/www/html/php/rb_new.php on line 3075

Deprecated: Return type of & RedBeanPHP\OODBBean::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 /var/www/html/php/rb_new.php on line 3113

Deprecated: Return type of RedBeanPHP\OODBBean::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 /var/www/html/php/rb_new.php on line 3057

Deprecated: Return type of RedBeanPHP\OODBBean::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 /var/www/html/php/rb_new.php on line 3094

Deprecated: Return type of RedBeanPHP\OODBBean::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/php/rb_new.php on line 3254

Deprecated: Return type of RedBeanPHP\OODBBean::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/php/rb_new.php on line 3862

Deprecated: PDOStatement::fetchAll(): Passing null to parameter #1 ($mode) of type int is deprecated in /var/www/html/php/rb_new.php on line 822

Deprecated: PDOStatement::fetchAll(): Passing null to parameter #1 ($mode) of type int is deprecated in /var/www/html/php/rb_new.php on line 822

Deprecated: PDOStatement::fetchAll(): Passing null to parameter #1 ($mode) of type int is deprecated in /var/www/html/php/rb_new.php on line 822

Deprecated: PDOStatement::fetchAll(): Passing null to parameter #1 ($mode) of type int is deprecated in /var/www/html/php/rb_new.php on line 822
ipsod commented 3 years ago

I confirmed that the file I'm using does contain the changes by running diff rb.php rb_new.php, and getting this output:

1145c1145
<       if ($connected) $this->connected = $connected;
---
>       if ($connected) $this->isConnected = $connected;
2061a2062
>    #[ReturnTypeWillChange]
3054a3056
>    #[ReturnTypeWillChange]
3071a3074
>    #[ReturnTypeWillChange]
3089a3093
>    #[ReturnTypeWillChange]
3107a3112
>    #[ReturnTypeWillChange]
3247a3253
>    #[ReturnTypeWillChange]
3854a3861
>    #[ReturnTypeWillChange]
4692a4700,4704
>    * @var string
>    */
>   protected $mask = NULL;
> 
>   /**
4697a4710
>    * @param string     $mask       meta mask to apply (optional)
4701c4714
<   public function __construct( $type, Repository $repository, Cursor $cursor )
---
>   public function __construct( $type, Repository $repository, Cursor $cursor, $mask = '__meta' )
4705a4719
>       $this->mask = $mask;
4720c4734
<           $beans = $this->repository->convertToBeans( $this->type, array( $row ) );
---
>           $beans = $this->repository->convertToBeans( $this->type, array( $row ), $this->mask );
13507c13521
<    * @return array
---
>    * @return OODBBean|NULL
13682a13697,13699
>    * @phpstan-param literal-string|null $sql
>    * @psalm-param   literal-string|null $sql
>    *
14062c14079
<    * @return array
---
>    * @return OODBBean
14092c14109
<    * @return array
---
>    * @return OODBBean
Lynesth commented 3 years ago

I guess it's supposed to be #[\ReturnTypeWillChange], not #[ReturnTypeWillChange].

gabordemooij commented 3 years ago

Thanks for pointing this out @Lynesth - Must have mistyped that annotation. Thanks @ipsod for testing it again. I have fixed the typo and I also fixed the null-warning you're getting. Hopefully it will work again, would you mind testing it again please?

Here is the new version: https://redbeanphp.com/downloads/RedBeanPHP5_7_1RC2.tar.gz

For now I will keep using the ReturnTypeWillChange, when PHP 9 comes around, I will introduce a patch for older PHP-versions and probably a separate package, so you'll get RedBeanPHP5_7_X-Mysql-PHP9plus.tar.gz and -PHPClassic or so. Too bad PHP is breaking backward compatibility, they had an impressive BC-record with PHP5-7. RedBeanPHP will remain backward compatible with PHP 5.3 though (we still have PHP 5.2 users!), for at least another 10 years or so . Once people choose for RedBeanPHP they have to be sure they can really depend on it.

ipsod commented 3 years ago

I get no warnings with this version. Thank you!

gabordemooij commented 3 years ago

Thanks for testing! If you encounter any other compat. issues pls let me know!

ipsod commented 3 years ago

I just found another deprecation warning:

 trim(): Passing null to parameter #1 ($string) of type string is deprecated in
/var/www/html/php/rb_new.php
on line
6191

Deprecated
ipsod commented 3 years ago

Another: Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/php/rb_new.php on line 6302

fabswt commented 2 years ago

Spotted this one (running v5.7.1):

trim(): Passing null to parameter #1 ($string) of type string is deprecated

File: /var/www/html/.../vendor/gabordemooij/redbean/RedBeanPHP/QueryWriter/AQueryWriter.php
Line: 869
prochor666 commented 2 years ago
trim(): Passing null to parameter #1 ($string) of type string is deprecated
File: D:\dev\...\vendor\gabordemooij\redbean\RedBeanPHP\QueryWriter\AQueryWriter.php (line: 869)

Working fix:

On line 869 REPLACE:

if ( trim( $sql ) === '' ) {

WITH:

if ( is_null($sql) || trim( $sql ) === '' ) {

Maybe not ideal, but it's working for me.