Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Silence notice thrown by php74 on array offset access of non-array types #382

Merged

Conversation

zehao-sean-huang
Copy link
Contributor


name: 🐛 Bug report --
about: PHP 7.4 Array Offset Access Throws out a Notice

Versions

  • scout-elastic-driver: 6.8.5
  • laravel/framwork: 5.8.38
  • php: 7.4.7
  • elasticsearch: 6.8.5

Description

When using laravel tinker, we tried the following command:

Model::search('text')->get(), and it outputs the following error message.

PHP Notice: Trying to access array offset on value of type int in <project_root>/.../src/ElasticEngine.php

Simple Fix

Just a one line change using the following syntax: $not_array['key'] ?? 0. This silences the error, enabling the code to execute normally and fall back to a normal value if the key is not found.

@@ -348,7 +348,7 @@ public function map(Builder $builder, $results, $model)
*/
public function getTotalCount($results)
{
return $results['hits']['total']['value'];
return $results['hits']['total']['value'] ?? 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is just one line and doesn't affect the existing functionality. Our team is blocked rn so we'd really appreciate it if we could get this change fixed :)

@zehao-sean-huang
Copy link
Contributor Author

zehao-sean-huang commented Aug 13, 2020

@babenkoivan

@babenkoivan babenkoivan merged commit 6daad2e into babenkoivan:master Aug 13, 2020
@babenkoivan
Copy link
Owner

@zehao-sean-huang merged and released in v4.2.3. But I recommend you to migrate to elastic-scout-driver and elastic-scout-driver-plus.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants