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

AccessType attribute constructor expects array #1531

Open
SimonTod opened this issue Jan 3, 2024 · 3 comments
Open

AccessType attribute constructor expects array #1531

SimonTod opened this issue Jan 3, 2024 · 3 comments

Comments

@SimonTod
Copy link

SimonTod commented Jan 3, 2024

Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no

As declared in the documentation, the next annotation works

use JMS\Serializer\Annotation\AccessType;

/** @AccessType("public_method") */
class User { }

But I could not make it work using the php attribute

use JMS\Serializer\Annotation\AccessType;

#[AccessType('public_method')]
class User { }

Error thrown :

Uncaught Error: JMS\Serializer\Annotation\AccessType::__construct(): Argument #1 ($values) must be of type array, string given

As we can see in https://github.com/schmittjoh/serializer/blob/master/src/Annotation/AccessType.php#L24 :

    public function __construct(array $values = [], ?string $type = null)
@SimonTod
Copy link
Author

SimonTod commented Jan 4, 2024

I fixed the issue with the next syntax :

use JMS\Serializer\Annotation\AccessType;

#[AccessType(type: 'public_method')]
class User { }

I think it would be a good thing to update the documentation

@scyzoryck
Copy link
Collaborator

Thanks for feedback! I think it is time to make docs Attributes first :)

@SimonTod
Copy link
Author

SimonTod commented Jan 8, 2024

There is a small section about it : Converting your annotations to attributes

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

No branches or pull requests

2 participants