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

Default typecasting should be applied for any View on set #1990

Closed
mkrecek234 opened this issue Feb 1, 2023 · 2 comments
Closed

Default typecasting should be applied for any View on set #1990

mkrecek234 opened this issue Feb 1, 2023 · 2 comments

Comments

@mkrecek234
Copy link
Contributor

Enforcing HTMLTemplate in #1989 to accept string only, makes coding unnecessarily cumbersome.

Why is PHP-standard typecasting not allowed here where model field is an integer?

\Atk4\Ui\Header::addTo($app, [$model->get('stock')]);

Simple code, simple PHP typecasting. Do we really want to enforce everyone to code like this?
\Atk4\Ui\Header::addTo($app, [(string) $model->get('stock')]);

Either, any view which is set a value to should continue to use PHP-default typecasting or it should behind the scenes use uiPersistence typecasting.

@mkrecek234 mkrecek234 changed the title Default PHP typecasting should be possible Default typecasting should be applied for any View on set Feb 1, 2023
@mvorisek
Copy link
Member

mvorisek commented Feb 1, 2023

with hintable, such problem is detected by phpstan, and was before #1989

in 95% of atk4/ui code we do accept string (strongly typed) strictly, so even if we fix this for Header/View constructor content/label, the issue will remain for other 95% cases

Also, opinionated, I wonder how purely numeric header is common/helpful to be supported - 'Stock #' . $model->get('stock') will cast the integer implicitly...

@mvorisek
Copy link
Member

It may be implemented in the future, but we need reliable idea how to address this. So far requiring everything typecasted to string is the best and the safest.

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

2 participants