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

Handling of Property Order when using Traits #1419

Open
Hanmac opened this issue Jul 1, 2022 · 3 comments
Open

Handling of Property Order when using Traits #1419

Hanmac opened this issue Jul 1, 2022 · 3 comments

Comments

@Hanmac
Copy link

Hanmac commented Jul 1, 2022

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

Steps required to reproduce the problem

use annotations on properties, and have some of them be inserted via traits:

trait T { protected $t; }
class C {
  protected $a;
  use T;
  protected $b;
}

Expected Result

i Expected the result that $t is serialized between $a and $b

Actual Result

But instead $t is serialized after $b.

i assume it has something to do with the order of the properties like:
(new ReflectionClass(C::class))->getProperties()

I assume that PHP can't detect at which position the use is called.

for a Possible Solution, a better way of ordering the Properties would be nice, like to give $a the @Order(-1) and $b the @Order( +1).
So when it would try to order after this new annotation, it would order them $a, $t, $b as i want.

The Reason

I have multiple classes that uses the same (block of) attributes over and over again, but because the xml needs to follow a specific sequence of elements, they need to be in a specific order.

@scyzoryck
Copy link
Collaborator

I'm afraid it seems to be impossible with Reflection - we would need to rewrite it to use AST instead.
May you can try to use AccessorOrder annotation?

@Hanmac
Copy link
Author

Hanmac commented Jul 13, 2022

AccessorOrder means i would need to use custom and to define the whole order again

if i had a way to define a relative order (-1 vs +1) i think it would be way cleaner

@pvm
Copy link

pvm commented Aug 7, 2024

I'm having the same issue, any news on this?

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

3 participants