yajra / laravel-oci8

Oracle DB driver for Laravel via OCI8

Home Page:https://yajrabox.com/docs/laravel-oci8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP 8.1 show Warning reset(): Calling reset() on an object is deprecated

jirapetr opened this issue · comments

Summary of problem or feature request

Laravel debugbar show lots of LOG.warnings:

warning: Return type of Yajra\Pdo\Oci8\Statement::bindColumn($column, &$variable, $dataType = null, $maxLength = -1, $options = null) should either be compatible with PDOStatement::bindColumn(string|int $column, mixed &$var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in ../vendor/yajra/laravel-pdo-via-oci8/src/Pdo/Oci8/Statement.php on line 223

warning: reset(): Calling reset() on an object is deprecated in ../vendor/yajra/laravel-pdo-via-oci8/src/Pdo/Oci8/Statement.php on line 650

I want no warning

Code snippet of problem

if ((is_array($row) || is_object($row)) && is_resource(reset($row))) {

System details

  • Ubuntu 20.04
  • PHP Version: 8.1
  • Laravel Version: 8.76
  • Laravel-OCI8 Version : 8.5

Thanks for reporting. I haven't had time to upgrade to 8.1 and still stuck with 7.4. If you can fix, please do not hesitate to submit a PR.

Just to confirm, will this be combined with Laravel 9 support seeing as that is now released?

@jamespavett Yes, any fixes on 8.x will be added on 9.x version if that is what you were referring to.

Also, would you be able to help reviewing this PR: yajra/pdo-via-oci8#95 if it fixes the issue?

Same issue here I have many deprecation logs for Calling reset().
PHP: 8.1.4
Laravel: 9.17

local.WARNING: reset(): Calling reset() on an object is deprecated in *\vendor\yajra\laravel-pdo-via-oci8\src\Pdo\Oci8\Statement.php on line 690

It's maybe the solution, in line 690 & 691 you need to replace the reset() with current() some discussion can be found here

 if ((is_array($row) || is_object($row)) && is_resource( reset($row) )) {
                $stmt = new self(reset($row)), $this->connection, $this->options);

update to

 if ((is_array($row) || is_object($row)) && is_resource( current( ( (array) $row) ) )) {
                $stmt = new self(current(((array) $row)), $this->connection, $this->options);

Update:
Maybe as official PHP here I just test the second solution and it's working.

$row = get_mangled_object_vars($row);
if ((is_array($row) || is_object($row)) && is_resource( reset ($row) )) {
                $stmt = new self( reset($row), $this->connection, $this->options);

Note: I did try both method to get raid of deprecation logs, I get same result with current( ((array) $row)) and $row = get_mangled_object_vars($row); before if condition

Please fix the issue and update the composer.json in Laravel OCI8 to use the last version of pdo-via-oci8 if required, also please update the name of pdo-via-oci8 in composer.json becuase it's still laravel-pdo-via-oci8, I get confused for find right place to check the issue.

Fixed via yajra/pdo-via-oci8#104 - v3.2.3. Thanks!