Git Product home page Git Product logo

Comments (4)

martin-schilling avatar martin-schilling commented on September 24, 2024 1

I was able to reproduce it. Not quite sure why but array_merge seems to be the problem:

<?php

$vpack1 = \Velocypack\Vpack::fromArray(array_merge([], ['test']));
$vpack2 = \Velocypack\Vpack::fromArray(['test']);


var_dump(phpversion());

var_dump(['test']);
var_dump(array_merge([], ['test']));
var_dump($vpack1->toJson());
var_dump($vpack2->toJson());

produces

string(5) "7.3.0"
array(1) {
  [0]=>
  string(4) "test"
}
array(1) {
  [0]=>
  string(4) "test"
}
string(12) "{"0":"test"}"
string(8) "["test"]"

from php-velocypack.

martin-schilling avatar martin-schilling commented on September 24, 2024 1

So this should solve the problem: c20c44e

The extension now pretty much uses the same checks that json_encode uses to determine if an array is numeric or not, therefore this kind of error should not pop up in the future again.

@sandrokeil Please try if this solves the problem 😄

from php-velocypack.

martin-schilling avatar martin-schilling commented on September 24, 2024

I found out a few more interesting things about this. First of all if you use array_merge with the arguments switched the problem is gone.
Then I tried json_encode and noticed that it works in all cases as one would expect. Therefore I have been looking at its implementation and found out that it not only uses the HT_IS_PACKED(myht) && HT_IS_WITHOUT_HOLES(myht) flags that are used here as well, but also loops through the entire array for checking if it is in fact a numeric one.
https://github.com/php/php-src/blob/a5fa51afbbd87bedeb1c5fd7c9a6cf3c971ab14c/ext/json/json_encoder.c#L49-L63

I am going to implement it the exact same way here as well to prevent issues with this in the future.

from php-velocypack.

sandrokeil avatar sandrokeil commented on September 24, 2024

All green again. 👍

from php-velocypack.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.