Skip to content

[String] allow string to be constructed with null #38260

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

Closed
kbond opened this issue Sep 21, 2020 · 3 comments · Fixed by #38269
Closed

[String] allow string to be constructed with null #38260

kbond opened this issue Sep 21, 2020 · 3 comments · Fixed by #38269
Labels

Comments

@kbond
Copy link
Member

kbond commented Sep 21, 2020

Description
Just recently started really using the component and am finding it annoying that a string can't be constructed with null (think nullable entity fields). Maybe at least the helper functions? I wanted to gauge interest before submitting a PR.

There was a PR accepted to allow this for the Twig StringExtension (twigphp/Twig#3259).

Example
Instead of s((string) $possibleNullString), it would be nice to just do s($possibleNullString).

@derrabus
Copy link
Member

And what should s(null) produce in that case?

@kbond
Copy link
Member Author

kbond commented Sep 21, 2020

The same as s((string) null) (s(''))

@nicolas-grekas
Copy link
Member

Why not, but only for the functions, not for the class' constructors, isn't it? Please send a PR so we can discuss the idea on actual code.

@xabbuh xabbuh added the String label Sep 22, 2020
@fabpot fabpot closed this as completed Sep 24, 2020
fabpot added a commit that referenced this issue Sep 24, 2020
This PR was submitted for the 5.1 branch but it was merged into the 5.2-dev branch instead.

Discussion
----------

[String] allow passing null to string functions

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #38260
| License       | MIT
| Doc PR        | n/a

I also added a default value for `s` to match the other functions.

Commits
-------

f20a318 [String] allow passing null to string functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants