Thanks to visit codestin.com
Credit goes to github.com

Skip to content

symfony/yaml PHP 8.1 Compatibility #52326

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
timnolte opened this issue Oct 27, 2023 · 15 comments · Fixed by #52334
Closed

symfony/yaml PHP 8.1 Compatibility #52326

timnolte opened this issue Oct 27, 2023 · 15 comments · Fixed by #52334

Comments

@timnolte
Copy link

Symfony version(s) affected

6.3.3

Description

The trim() method will no longer accept a null value.

https://github.com/symfony/yaml/blob/6.3/Inline.php#L62

Deprecation warnings are thrown when this method is used.

How to reproduce

Call `Inline::parse( null );

Possible Solution

Need to validate that $value is not null before attempting to trim().

Additional Context

No response

@nicolas-grekas
Copy link
Member

This class is internal.
Did you find a way to do this call while using only non-internal API?

@stof
Copy link
Member

stof commented Oct 27, 2023

@nicolas-grekas we should still check why our argument has a default value being null though...

@xabbuh xabbuh added the Yaml label Oct 27, 2023
@timnolte
Copy link
Author

@nicolas-grekas I think we probably need to dig in deeper to how we are using this method tbh. So I'll do some digging into this as well.

@ghost
Copy link

ghost commented Oct 27, 2023

This class is internal. Did you find a way to do this call while using only non-internal API?

I think the author reports deprecation warnings he wants to get rid of.

@stof
Copy link
Member

stof commented Oct 27, 2023

@javaDeveloperKid but then, we still need to know which code path triggers that deprecation, to find where we end up passing null to this method.

@ghost
Copy link

ghost commented Oct 27, 2023

@stof we can't rule out that someone violates @internal annotation

@timnolte
Copy link
Author

timnolte commented Oct 27, 2023

@javaDeveloperKid & @stof if you look at the function the default value if none is supplied is null. https://github.com/symfony/yaml/blob/6.3/Inline.php#L58

public static function parse(string $value = null, int $flags = 0, array &$references = []): mixed

@timnolte
Copy link
Author

timnolte commented Oct 27, 2023

FYI, I patched this code using a null check with an early return before the trim() even happens.

@GromNaN
Copy link
Member

GromNaN commented Oct 27, 2023

The class is marked as @internal. This method must not be called outside of the Yaml component. Everywhere we call it with a string as first argument. There is no supported case of passing null as first argument.
If your code uses this function, you must fix it.
I submitted a PR for 6.4 to disallow null value #52334

@timnolte
Copy link
Author

timnolte commented Oct 27, 2023

@GromNaN FYI, we are not calling that method directly actually. We are calling Yaml::dump() & Yaml::parse(). https://github.com/symfony/yaml/blob/6.3/Yaml.php#L91
https://github.com/symfony/yaml/blob/6.3/Yaml.php#L73

@GromNaN
Copy link
Member

GromNaN commented Oct 27, 2023

Could you provide an example? So that we can fix the Yaml class if necessary.

@timnolte
Copy link
Author

@GromNaN our call is just this: https://github.com/forumone/wp-cfm/blob/develop/includes/class-readwrite.php#L204

I believe we can probably squash the deprecation warning by ensuring we aren't passing a null value into the Yaml::parse() method.

@GromNaN
Copy link
Member

GromNaN commented Oct 27, 2023

You are the using symfony/yaml: 3.3.6. This explains why you don't have the type check when calling Yaml::parse(null). You will have to fix the call on your side since this unmaintained version will not be updated.

@GromNaN GromNaN closed this as completed Oct 27, 2023
@timnolte
Copy link
Author

@GromNaN actually I have an open PR to upgrade to v5. https://github.com/forumone/wp-cfm/blob/fix/135-php81-deprecations/composer.json#L29

@GromNaN
Copy link
Member

GromNaN commented Oct 28, 2023

👍🏻 In 5.4, only strings are accepted by Yaml::parse().

fabpot added a commit that referenced this issue Oct 28, 2023
…rKid)

This PR was merged into the 5.4 branch.

Discussion
----------

[Yaml] Fix deprecated passing null to trim()

| Q             | A
| ------------- | ---
| Branch?       |5.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Closes #52326 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

Commits
-------

54fc3c5 Fix passing null to trim()
fabpot added a commit that referenced this issue Oct 28, 2023
This PR was merged into the 6.4 branch.

Discussion
----------

[Yaml]  `Inline::parse(null)` not allowed

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #52326
| License       | MIT

It's only called with string values in the Yaml component.

This class is internal. It allows to change the arg type.
The arg type was documented as `string`.
7b1715b#diff-1d97fcfb29e99f0200c3952e9a1a11c4b9f825c0f5ad4d4515b9b1805f8c988eR47

Commits
-------

834e0ab Passing null to Inline::parse is not allowed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants