ID: 31601 Updated by: php-bugs@lists.php.net Reported By: phpbugs at kaiundina dot de -Status: Feedback +Status: No Feedback Bug Type: Zend Engine 2 problem Operating System: Win XP prof/Apache 2 PHP Version: 5.0.2 New Comment:
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". Previous Comments: ------------------------------------------------------------------------ [2005-02-28 21:00:38] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-01-19 00:19:20] phpbugs at kaiundina dot de 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31601&edit=1