peachpiecompiler/peachpie

strange compiler behavior when modifier is "protected"

N0zzy opened this issue · 1 comments

N0zzy commented

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

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.