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

MessageFormatter throws error on unused datetime value #16814

Closed
naturefund-falk opened this issue Nov 15, 2024 · 4 comments
Closed

MessageFormatter throws error on unused datetime value #16814

naturefund-falk opened this issue Nov 15, 2024 · 4 comments

Comments

@naturefund-falk
Copy link

naturefund-falk commented Nov 15, 2024

Description

The following code:

<?php
$fmt = new MessageFormatter('de', 'Beispiel ohne Benutzung');

echo $fmt->format(['payed' => new DateTimeImmutable()]);

Resulted in this output:

PHP Fatal error:  Uncaught Error: Object of class DateTimeImmutable could not be converted to string in /home/development/fst/src/tests/messageFormatter.php:5

But I expected this output instead:

No error, because value not used. No reason to convert the datetime value to a string

Intl data

Internationalization support => enabled
ICU version => 72.1
ICU Data version => 72.1
ICU TZData version => 2022e
ICU Unicode version => 15.0

PHP Version

PHP 8.2.24

Operating System

Debian 12

@devnexen
Copy link
Member

I ll have a look into this, your report makes sense tough.

@devnexen devnexen self-assigned this Nov 15, 2024
@devnexen devnexen changed the title MessageFormatter throws error on unused datedate value MessageFormatter throws error on unused datetime value Nov 15, 2024
devnexen added a commit to devnexen/php-src that referenced this issue Nov 15, 2024
@nielsdos
Copy link
Member

I'm closing this as "not a bug" as according to the conversation in #16816.

@nielsdos nielsdos closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2024
@naturefund-falk
Copy link
Author

The Problem may be on another level. Because the value isnt used, the helper function (from the mentioned conversation) does not know that the value is a date value (and could be converted to a string as a date).
If i use the value in the message as '{ payed, date }', it all works fine.
The reason for the (possible) missing parameter is that the message itself comes from a translation source and the translator may drop this parameter from the message in his translation. At the end i have a translation which work in some languages and in some not.
Maybe the question in the messageformatter_helper.cpp is, why it does not know that the value is a date, i mean it as a DateTimeImmutable object.

@nielsdos
Copy link
Member

I think I understand your concern. I'm not entirely sure it's possible to handle this in a consistent way in the extension interface to the C library though...

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

4 participants