Skip to content

Fix PHP 8.5 deprecations: roman_year nullable + (double)→(float) cast#2

Open
luca9692 wants to merge 2 commits into
padosoft:masterfrom
luca9692:master
Open

Fix PHP 8.5 deprecations: roman_year nullable + (double)→(float) cast#2
luca9692 wants to merge 2 commits into
padosoft:masterfrom
luca9692:master

Conversation

@luca9692
Copy link
Copy Markdown

What

Two PHP 8.5 deprecation fixes:

  1. src/datetime.php:212roman_year(int $year = null)roman_year(?int $year = null) (PHP 8.4+ requires explicit nullable on non-nullable type with default null)
  2. src/validation.php:130(double)$value cast → (float)$value (PHP 8.5 deprecates non-canonical (double) cast)

Why

Used by gescat-laravel on PHP 8.5 — these surface as runtime Deprecated notices and will become fatal in PHP 8.6+.

Compatibility

Both changes are semantic no-ops (same behavior, explicit syntax). No breaking changes.

Patches

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses PHP 8.5 deprecation notices by updating two helper functions in the support library to use canonical/explicit typing and casting syntax.

Changes:

  • Update roman_year() to explicitly accept nullable input (?int $year = null) to avoid deprecation for non-nullable typed params with null defaults.
  • Replace deprecated (double)$value cast with canonical (float)$value in isIntegerFloatingPoint().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/datetime.php Makes roman_year() parameter explicitly nullable to avoid PHP 8.4+ deprecation notices.
src/validation.php Switches (double) to (float) cast in integer-floating-point validation logic for PHP 8.5 compatibility.
Comments suppressed due to low confidence (1)

src/datetime.php:216

  • Now that the parameter is typed as ?int, the is_numeric($year) check is effectively just a null check (ints are always numeric). Using $year === null (or renaming the condition/comment) would make the intent clearer and avoid implying non-int inputs are expected.
function roman_year(?int $year = null): string
{
    if (!is_numeric($year)) {
        $year = (int)date('Y');
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/validation.php
Comment on lines +130 to 131
&& ((int)((float)$value) == $value || (int)$value == $value || strpos(strtoupper((string)$value),
'E') === false);
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