Skip to content

Fixed StdObject conversion for null values in Sheet map arrayable row #4293

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

Open
wants to merge 1 commit into
base: 3.1
Choose a base branch
from

Conversation

dmyers
Copy link

@dmyers dmyers commented Apr 16, 2025

1️⃣ Why should it be added? What are the benefits of this change?

Fixes an issue I ran into with the mapArrayableRow() method with null values since the method signature has an array return type a null value breaks this and it crashes. I believe it is a good change to apply for all to fix the problem.

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.

No.

3️⃣ Does it include tests, if possible?

I have not just yet. I will try to see about this.

4️⃣ Any drawbacks? Possible breaking changes?

I do not believe so.

5️⃣ Mark the following tasks as done:

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression.

6️⃣ Thanks for contributing! 🙌

@dmyers dmyers marked this pull request as ready for review April 16, 2025 21:32
@dmyers
Copy link
Author

dmyers commented Apr 18, 2025

After doing more research and testing. I found that the issue actually is that the approach to convert stdClass objects to arrays using json_encode(json_decode($row), true) which can return null values.

In my case I have a pretty simple table that has one column that is a binary column and I'm using DB::table('table')->get() to get the data. The issue is that the binary column is being converted to a string in the json_encode() and then to an array in the json_decode(), but somehow the UTF-8 charset between those steps causes a generic "syntax error" message when using json_last_error_msg() right after. This has led me to believe that json_encode() method does not fully support binary data.

I was able to test this a lot and found another solution is to just cast the stdClass object to an array directly using (array) $row and is both simple and I believe will work for all the scenarios that the JSON approach currently works for and of course this other case too.

Curious to get your thoughts. Currently I had to manually setup a mapping to prevent the mapArrayableRow() from being used so that way I can patch it in my codebase, but I'd like to get this into the package if you think this is a good solution.

@patrickbrouwers
Copy link
Member

The fix seems fine, however it would be great to have a unit test for this

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

Successfully merging this pull request may close these issues.

2 participants