Skip to content

Get last errors to return false#70

Merged
kylekatarnls merged 6 commits intoCarbonPHP:masterfrom
MizouziE:get-last-errors-to-return-false
Dec 3, 2025
Merged

Get last errors to return false#70
kylekatarnls merged 6 commits intoCarbonPHP:masterfrom
MizouziE:get-last-errors-to-return-false

Conversation

@MizouziE
Copy link
Copy Markdown
Contributor

Closes briannesbitt/Carbon#3224

As described in the above issue (on the parent repo of this one), the non-expected behaviour of Carbon::getLastErrors() returning an array, albeit full of empty arrays and zero counts, is not equivalent to DateTime::getLastErrors(). This makes it a little less than ideal to work with when using this method in conjunction with Carbon::canBeCreatedFromFormat() to do edge case date validation.

I imagine that people using this library may have their own work-around in place for this, so I feel like this would be considered a breaking change and I'm unsure what the best approach would be to get this behaviour aligned with the DateTime namesake.

I'd still like to make these changes visible and hope to open a discussion, be it worthy of one, about how it can be done.

TIA

- Change the type on static property
- empty check on filtered array
- actually return false if empty
@kylekatarnls kylekatarnls added this to the 3.11.0 milestone Nov 20, 2025
@kylekatarnls kylekatarnls modified the milestones: 3.11.0, 3.12 Dec 2, 2025
Comment thread src/Carbon/Traits/Creator.php Outdated
@kylekatarnls
Copy link
Copy Markdown
Contributor

Now, we have an incompatibility with PHP 8.1 (because PHP actually returned this array before 8.2), but I would be fine to just add #[RequiresPhp('>=8.2')] on those tests to skip PHP 8.1 and accept the difference of behavior depending on the version.

@MizouziE
Copy link
Copy Markdown
Contributor Author

MizouziE commented Dec 3, 2025

Does this mean that the version of Carbon this would be tagged in would require PHP ^8.2 also?

@kylekatarnls
Copy link
Copy Markdown
Contributor

kylekatarnls commented Dec 3, 2025

Does this mean that the version of Carbon this would be tagged in would require PHP ^8.2 also?

No, this just means that the behavior of returning false is tested only for PHP >= 8.2 (then we don't check nor guarantee what result you would get for any version lower than that).

I don't expect it to be an issue anyway because PHP 8.1 no longer receives any update, so it shouldn't change and the behavior will be unchanged compared to current version of Carbon for people using PHP 8.1, so actually the small breaking change that can create a bit of friction for people relying on the array result is for the users on PHP >= 8.2 when they'll upgrade to the next version of Carbon or later for people upgrading from PHP 8.1 to higher (which is not great to happen on a minor version but would probably still fit as small-enough for our breaking-change policy)

@kylekatarnls kylekatarnls merged commit f781760 into CarbonPHP:master Dec 3, 2025
20 checks passed
@kylekatarnls kylekatarnls modified the milestones: 3.12.0, 3.11.1 Jan 29, 2026
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.

Carbon::getLastErrors() behaves differently to DateTime::getLastErrors()

2 participants