Skip to content
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

Invalid numeric literal with mktime() in 2-digit month 08 and 09 #18124

Closed
ophian opened this issue Mar 21, 2025 · 4 comments
Closed

Invalid numeric literal with mktime() in 2-digit month 08 and 09 #18124

ophian opened this issue Mar 21, 2025 · 4 comments

Comments

@ophian
Copy link

ophian commented Mar 21, 2025

Description

The following code:

<?php

// normal behavior January to July
....
$ts04 = mktime(00, 12, 00, 04, 1, 2024);
$ts05 = mktime(00, 12, 00, 05, 1, 2024);
$ts06 = mktime(00, 12, 00, 06, 1, 2024);
$ts07 = mktime(00, 12, 00, 07, 1, 2024);

// failing behavior in August and September
$ts08 = mktime(00, 12, 00, 08, 1, 2024);
$ts8 = mktime(00, 12, 00, 8, 1, 2024); // fixed
$ts09 = mktime(00, 12, 00, 09, 1, 2024);
$ts9 = mktime(00, 12, 00, 9, 1, 2024); // fixed

echo 'TNOW = '.date('d-m-Y H:i:s', $ts04)."<br>\n";
echo 'TNOW = '.date('d-m-Y H:i:s', $ts05)."<br>\n";
echo 'TNOW = '.date('d-m-Y H:i:s', $ts06)."<br>\n";
echo 'TNOW = '.date('d-m-Y H:i:s', $ts07)."<br>\n";

echo 'TNOW = '.date('d-m-Y H:i:s', $ts08)."<br>\n";
echo 'TNOW = '.date('d-m-Y H:i:s', $ts8)."<br>\n";

echo 'TNOW = '.date('d-m-Y H:i:s', $ts09)."<br>\n";
echo 'TNOW = '.date('d-m-Y H:i:s', $ts9)."<br>\n";
<?php

Resulted in this output: (for $ts08 and $ts09)

Parse error: Invalid numeric literal in ...

while $ts8 and $ts9 work OK and also all $ts0x until.

But I expected this output instead:

Output for 8.2.0 - 8.2.28, 8.3.0 - 8.3.19, 8.4.1 - 8.4.5
    TNOW = 01-04-2024 00:12:00
    TNOW = 01-05-2024 00:12:00
    TNOW = 01-06-2024 00:12:00
    TNOW = 01-07-2024 00:12:00
    TNOW = 01-08-2024 00:12:00
    TNOW = 01-09-2024 00:12:00

Am I missing something?

PHP Version

PHP 8.2.0 - 8.2.28, 8.3.0 - 8.3.19, 8.4.1 - 8.4.5

Operating System

No response

@kallesommernielsen
Copy link

This is because you use a zero-prefix on numbers, that will be interpreted as an octal and is the intended behavior

@kallesommernielsen kallesommernielsen closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2025
@ophian
Copy link
Author

ophian commented Mar 21, 2025

Can you then explain to me why 01 to 07 works and 08 and 09 don't ? What is the difference ?

@iluuu1994
Copy link
Member

Because octal is base-8. It only contains digits from 0-7.

@ophian
Copy link
Author

ophian commented Mar 21, 2025

Thank you @iluuu1994. Thats is an answer for my question that makes sense to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants