Description:
------------
I have the following problem using the 'self'-operator for static variable initialisation:
I created a class ('Item' in the reproduce code) persisting of the following elements:
- class-constants containing key-strings
- a static variable containing an array using the above constants as associative keys. The array was preinitialized with some values. As nonation for the keys I used 'self::CONST_NAME' ('self::ARRAY_KEY' in the example)
The following situations occurred:
case 1:
The first instance was created in scope of another class' constructor ('Container' in the example).
First I wondered why he was throwing a notice telling me the constant called 'self::ARRAY_KEY' didn't exist, then I figured out that he was searching for it in the wrong class. He tried to use the class 'Container' to initialize the static members of the 'Item' class. Declaring the constant in the 'Container'-class again caused the message to disappear.
case 2:
A dummy instance was created in scope of the class holding the static member.
Now everything worked fine. The class' constructor was called from a static method of the same class.
case 3:
I tried to directly access the static member (array) from outside any class without having created an instance of it before.
In this case I receive a fatal error telling me "Cannot access self:: when no class scope is active"
A workaround would be to omit the self-operator when used in static-initialisations and use the class' name instead.
another strange thing (might be a different bug - please tell me if it is):
When the static array is filled and returned, the key's order is different from that specified in the source. Entries having constant keys (literally entered in the source code) appear before those receiving their key from a class-constant. Each 'group' is ordered as expected for itself.
let me know, if the needed information is complete.
thanks for processing
Reproduce code:
---------------
http://kaiundina.de/bugs/selfbug.php5.txt
(The switch block at the end of the code shows the different use cases and their respective output)
Expected result:
----------------
The static members should be initialized using the constants as declared in the own class rather than using constants declared in the scope of the script that creates the first instance of the class.
In other words:
The 'self' operator should always refer to the class in which it appears when used for initialisation of static members.
Actual result:
--------------
The 'self'-operator, when used for initialisation of static members, refers to the class (if present) that executes the first 'new'-statement for the class containing the static member.

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

[2005-08-04 19:47 UTC] bwishan at gmail dot com

I'm experiencing the same problem on PHP 5.0.4. Has there been any update to this?

[2006-02-28 23:23 UTC] php at kaiundina dot de

The Problem seems to be fixed in 5.1.2
The arrays are now ordered correctly (case 1 and 2) and the error in case 3 doesn't occur any more.