Comments (4)
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.
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.
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.
All green again.
from php-velocypack.
Related Issues (9)
- Add Exceptions HOT 1
- Transactions not working HOT 3
- Add subvalue access that returns a new Vpack instead of a PHP value
- Add support for building and modifying Vpacks HOT 1
- Implement Traversable interface
- Wrap more Builder and Slice functionality
- Add support for BuilderOptions HOT 1
- Disable sorting on toJson / toArray HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-velocypack.