-
Notifications
You must be signed in to change notification settings - Fork 354
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
An error occurred while verifying the array #525
Comments
@zh-five which version of the library are you using? I just tried your sample with the latest version and the schema failed to validate as expected. |
Scratch that, the schema does fail validation, but there's some kind of problem with |
@erayd This will probably sound familiar, but the issue here is that he's passing in an associative array for the schema (the Not sure how to proceed. We could:
Any thoughts? |
@shmax I think we call this user error, and don't fix it.
That last point is the important one for me I think - guessing feels inappropriate in this case. There's nothing preventing the user from doing their own deep casting, and the user knows much more about their schema than we do - so they can make the correct decisions rather than blindly guessing and hoping it's right, which is what we would have to do. |
It's user error, but you can't really blame him for it; all of the samples in the main README support what he's doing. The only hint suggesting the more recommended usage I've noticed is a vaguely-worded comment on validate (not Deep casting may be slow, but we seem to be encouraging it as a best practice in our own documentation, and furthermore, it turns out we're already resigned to taking a stab at it in at least one place (it doesn't save us here, because I fired up my own codebase and dug around a bit. I have no idea what other people do, but I encode my schemas as php files. As you know, PHP doesn't really have what you would call an object literal, so I have to use associative arrays. To convert them to objects, I do one of these:
I added a timer on one of my heavier pages and totaled up the time spent on deep casting about 50 calls. The total was just under a tenth of a second. Not terrible, especially with the debugger on on a local machine, but given a preference I would rather not have to cast at all and get that time back. Even if I were to store JSON files (which I can't really do, because my schema files are littered with const references and other bits of domain knowledge from my PHP codebase), I would still have to run them through
Can you expand on that a bit? I'm wondering if we should just make a reasonable effort to support associative schemas. That would remove the need to cast from my end, and issues like the one we have here could be tested and dealt with. |
@erayd / @shmax maybe can pick this one up to make a decision and complete the issue? I get the points both of you are making. But maybe want to add one consideration which is availability/time. Since this project is being not very active, opening up the deep casting option can lead to more bugs/questions etc. Which in my opinion will require even more time. Picking the option to not support shallow casted objects nor do deep casting on the users behalf is the safest option and would only require once in a while answering to an issue report that we don't support such scenarios |
I think the implicit decision made by @erayd all those years ago was to consider it user error, which is fine with me. Feel free to close. |
test by PHP5.6
The text was updated successfully, but these errors were encountered: