Skip to content

Ignore the already safe date() function #665

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

cedric-anne
Copy link
Contributor

@cedric-anne cedric-anne commented May 13, 2025

In PHP < 8.0, passing an invalid timestamp parameter value to the date() function was triggering a warning and a false value was returned.

// PHP 7.4

var_dump(date('Y-m-d', 'not-a-date'));
// Warning: date() expects parameter 2 to be int, string given in Command line code on line 1
// bool(false)

Since PHP 8.0, an error is thrown in this specific case.

// PHP 8.0

var_dump(date('Y-m-d', 'not-a-date'));
// Fatal error: Uncaught TypeError: date(): Argument #2 ($timestamp) must be of type ?int, string given in Command line code:1

Still, the corresponding PHP doc has only been fixed in PHP 8.4 and remained Returns a formatted date string. If a non-numeric value is used for <parameter>timestamp</parameter>, &false; is returned and an <constant>E_WARNING</constant> level error is emitted. in previous PHP 8.x version.

@cedric-anne cedric-anne marked this pull request as draft May 13, 2025 12:26
@cedric-anne
Copy link
Contributor Author

I put this back to draft to make a unique PR with all the fixes, in order to prevent conflicting PRs.

@cedric-anne cedric-anne changed the title Ignore the already safe date() function Ignore already safe functions May 13, 2025
@cedric-anne cedric-anne marked this pull request as ready for review May 13, 2025 12:49
@silasjoisten
Copy link
Collaborator

@cedric-anne thank you! Can you please split this PR for each function into a different PR?

@cedric-anne
Copy link
Contributor Author

@cedric-anne thank you! Can you please split this PR for each function into a different PR?

I can, but they will conflict each other, so I will wait for each one to be merged before opening the next one. First one is #666 .

@silasjoisten
Copy link
Collaborator

@cedric-anne ready when you are ;)

@silasjoisten
Copy link
Collaborator

silasjoisten commented May 13, 2025

refs #666
refs #668
refs #669

@cedric-anne cedric-anne changed the title Ignore already safe functions Ignore the already safe date() function May 13, 2025
@cedric-anne
Copy link
Contributor Author

I rebased the current PR to include only the initial date() function fix.

Copy link
Collaborator

@silasjoisten silasjoisten left a comment

Choose a reason for hiding this comment

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

Good Job thanks!

@silasjoisten silasjoisten merged commit 991659a into thecodingmachine:master May 13, 2025
10 checks passed
@silasjoisten
Copy link
Collaborator

released in v3.2.0

@cedric-anne cedric-anne deleted the fix/date branch May 13, 2025 15:10
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