Skip to content

fix: TypeError in DataCaster initialization - #9738

Merged
paulbalandan merged 4 commits into
codeigniter4:developfrom
neznaika0:fix/datacaster-error
Dec 11, 2025
Merged

fix: TypeError in DataCaster initialization#9738
paulbalandan merged 4 commits into
codeigniter4:developfrom
neznaika0:fix/datacaster-error

Conversation

@neznaika0

Copy link
Copy Markdown
Contributor

Description

  • Fixed a bug where new DataCaster() caused the error TypeError: array_merge(): Argument #2 must be of type array, null given
  • Added a method check for castAs() and a test.
  • PHPDoc has been cleaned in BaseCast

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@neznaika0

Copy link
Copy Markdown
ContributorAuthor

The two checks conflict. What is the best way to fix it?
Update PHPDoc, add ignore, or remove exception?

@michalsn

Copy link
Copy Markdown
Member

Do you think this exception is necessary? The PHPDoc already makes it clear.

@neznaika0

neznaika0 commented Oct 3, 2025

Copy link
Copy Markdown
ContributorAuthor

phpDoc will not help if the user uses a different method (in notepad++).
Secondly, I've been thinking about it too. Then we can remove the exception and translation.

@michalsn

Copy link
Copy Markdown
Member

Then we can remove the exception and transfer.

I'm afraid I don't fully understand what you mean.

Since this isn't directly used by the end user, I'd stick with the PHPDoc. It has worked fine so far - unless there's a specific reason for adding this check?

@neznaika0

Copy link
Copy Markdown
ContributorAuthor

Sorry. Typo "translation".
Yes, it works. Then we have the dead code in the CastException. I decided that the check is necessary if an exception is planned. Or delete exception method.

@michalsn

Copy link
Copy Markdown
Member

This exception was previously used in the entity cast.

Let's hold off for now and hear what others think. If you feel it's more valuable to keep the exception and make the PHPDoc less strict, that's fine too.

Comment threadsystem/DataCaster/DataCaster.php Outdated
Comment threadsystem/DataCaster/DataCaster.php Outdated
Comment threadsystem/DataCaster/DataCaster.php
Comment threadsystem/Entity/Cast/BaseCast.php Outdated
@neznaika0
neznaika0force-pushed the fix/datacaster-error branch from c3d4e15 to cb3d4bfCompareOctober 4, 2025 09:43
@paulbalandanpaulbalandan changed the title fix: TypeError in DataCaster initializationfix: TypeError in DataCaster initializationOct 5, 2025
Comment threadsystem/DataCaster/DataCaster.php Outdated
Comment threadsystem/DataCaster/DataCaster.php
@paulbalandan
paulbalandan merged commit e4bbe32 into codeigniter4:developDec 11, 2025
49 checks passed
@paulbalandan

Copy link
Copy Markdown
Member

Thank you, @neznaika0

@neznaika0
neznaika0 deleted the fix/datacaster-error branch January 12, 2026 10:19
Sign up for freeto 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.

4 participants

@neznaika0@michalsn@paulbalandan@samsonasik