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

strange compiler behavior when modifier is "protected" #1112

Closed
N0zzy opened this issue May 7, 2023 · 1 comment
Closed

strange compiler behavior when modifier is "protected" #1112

N0zzy opened this issue May 7, 2023 · 1 comment

Comments

@N0zzy
Copy link

N0zzy commented May 7, 2023

Greetings. I observe strange behavior of the pie and reflection. when creating a class property using a php script with modifiers protected static - pie compiles in static as public and reflection points to this fact. is this a bug?

1
2

@jakubmisek
Copy link
Member

Hi,

This is by purpose; PHP static and .NET static behave differently. In PHP, a static property is static within the current request only. In .NET, static would be across all the requests.

To overcome this difference, PeachPie puts static properties into a nested class _statics, and creates a single instance for each request if needed.

Details at https://docs.peachpie.io/api/assembly/compiled-class/#additional-class-members

If it would be static, its value would be shared by all threads and all requests which would break the PHP behavior.

--

If you need a property, that is truly static (in a .NET manner), you can annotate it with Doc Comment @appstatic:

/*
 * field
 * @appstatic
 */
protected static $dTest;

This will create a property which value is shared across all requests - you can use it as optimization for example.

@N0zzy N0zzy closed this as completed May 8, 2023
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