Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Trying to access array offset on value of type int #292

Open
karvex opened this issue Mar 10, 2022 · 3 comments
Open

Error: Trying to access array offset on value of type int #292

karvex opened this issue Mar 10, 2022 · 3 comments

Comments

@karvex
Copy link

karvex commented Mar 10, 2022

It works with ArangoDB Queries UI, but not with triagens/arangodb v3.6.0.

I am using the following versions:

  • php v7.4.26
  • arangodb v3.9
  • triagens/arangodb v3.6.0
$query = '
    FOR c in cars
        LET carSeats = (
            FOR s in c.seats
            RETURN s
        )
    RETURN carSeats';
$response = DB::statement($query, []);

Callstack:
[2022-03-10 16:16:22] local.ERROR: Trying to access array offset on value of type int {"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type int at /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Document.php:299)
[stacktrace]
#0 /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Document.php(299): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to acces...', '/var/www/api/re...', 299, Array)
#1 /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Document.php(179): ArangoDBClient\Document->set(0, Array)
#2 /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Cursor.php(470): ArangoDBClient\Document::createFromArray(Array, Array)
#3 /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Cursor.php(408): ArangoDBClient\Cursor->addDocumentsFromArray(Array)
#4 /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Cursor.php(227): ArangoDBClient\Cursor->add(Array)
#5 /var/www/api/repository/vendor/triagens/arangodb/lib/ArangoDBClient/Statement.php(321): ArangoDBClient\Cursor->__construct(Object(ArangoDBClient\Connection), Array, Array)
#6 /var/www/api/repository/app/Arangodb/Connection.php(204): ArangoDBClient\Statement->execute()
#7 /var/www/api/repository/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php(388): App\Arangodb\Connection->statement('
FO...')
#8 /var/www/api/repository/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Database\DatabaseManager->__call('statement', Array)
#9 /var/www/api/repository/app/Repositories/Listing.php(257): Illuminate\Support\Facades\Facade::__callStatic('statement', Array)

Anyone having the same problem and found a solution?

@karvex karvex changed the title Trying to access array offset on value of type int Error: Trying to access array offset on value of type int Mar 10, 2022
@krkrTac
Copy link

krkrTac commented Apr 15, 2022

Hi @karvex

I have maybe the same issue when I want to access a specific key in document like RETURN DOCUMENT('collection/_key').myKey or FOR doc IN collection FILTER doc._key == '_key' RETURN doc.myKey
PHP launch NOTICE :
Trying to access array offset on value of type int in .../vendor/triagens/arangodb/lib/ArangoDBClient/Document.php on line 304
I fix temporary the issue when I check $key is a string
if (is_string($key) && $key[0] === '_') {
But I think is not enough to fix your issue

@mtzonev
Copy link

mtzonev commented Feb 24, 2023

Apparently this is still broken a year later:

  • php v8.0
  • arangodb v3.9.4
  • triagens/arangodb v3.8.0

It seems to happen when the resultset is a generic array of other arrays or objects and not native documents.

I came up with a very similar fix to the one posted by @krkrTac.

@jsteemann
Copy link
Contributor

@mtzonev :
The driver tries to turn the query result into an array of Document objects by default. This will not work if the returned data aren't actually documents.
In this case, please try setting the _flat option of the statement as follows:

        $statement = new Statement($connection, ['_flat' => true]);
        $statement->setQuery('RETURN (FOR i IN 1..1000 RETURN CONCAT("test", i))');
        $cursor = $statement->execute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants