php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45910 Cannot declare self-referencing constant
Submitted: 2008-08-25 18:10 UTC Modified: 2008-08-26 08:38 UTC
From: s dot tretter at szene1 dot at Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.0alpha1 OS: Linux
Private report: No CVE-ID: None
 [2008-08-25 18:10 UTC] s dot tretter at szene1 dot at
Description:
------------
The problem is that the same script worked in php5.2.6, but in php5.3 it results in a "Fatal error: Cannot declare self-referencing constant 'n61' in ..."

There is an array that uses many constants to set the array with values. If I execute a method of the class this error message stops the execution..but the line of the code has nothing todo with this array! strange error... just let me send my test code, u will see it yourself.
If i modify the array, remove the lines that php is complain about, some lines and so on.. it works.. but these lines are not differnt to the ohter lines..!? I don't understand it.

Also tried with latest cvs snapshot

Reproduce code:
---------------
I have a test script, but I don't wanna publish the code... May I send it directly to a php developer?

Expected result:
----------------
like in php5.2.6 this code should work!

Actual result:
--------------
Fatal error: Cannot declare self-referencing constant 'n61' in /..../test.php on line 132


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-25 18:34 UTC] s dot tretter at szene1 dot at
okay here a test script...
<?php
        class Test
        {
                const HOST_SK = 13;

                const NOSHOW = 'n77';

                const CONTENT_AD                = 'n10';
                const CONTENT_AD_MAIN           = 'n5';
                const CONTENT_AD_SALE           = 'n15';
                const SKYSCRAPER                = 'n4';
                const SITEBAR                   = 'n6';
                const BIGSIZE_BANNER            = 'n3';
                const CONTENT_USERPAGE          = self::NOSHOW;

                const HOCKEY1_SKYSCRAPER        = 'n4';
                const HOCKEY2_BIGSIZE_BANNER    = 'n3';

                const SPECIAL_FOTO_SKYSCRAPER   = 'n14';

                private static $host_matching   = array(
                        self::HOST_SK => array(
                                self::CONTENT_AD                        => 'n64',
                                self::CONTENT_AD_MAIN                   => 'n63',
                                self::CONTENT_AD_SALE                   => 'n65',
                                self::SKYSCRAPER                        => 'n62',
                                self::SITEBAR                           => 'n66',
                                self::BIGSIZE_BANNER                    => 'n61',
                                self::HOCKEY1_SKYSCRAPER                        => 'n62',
                                self::HOCKEY2_BIGSIZE_BANNER            => 'n61',
                                self::SPECIAL_FOTO_SKYSCRAPER           => 'n67',
                                self::CONTENT_USERPAGE                  => self::NOSHOW
                        )
                );

                public static $objects = array();

                public static function addElement($object)
                {
                        self::$objects[] = $object;
                }

}

Test::addElement("socha");
?>
 [2008-08-25 19:28 UTC] felipe@php.net
Here's a simple script based in your example:

class foo {
	const AAA = 'x';
	const BBB = 'a';
	const CCC = 'a';
	const DDD = self::AAA;

	private static $foo = array(
		self::BBB	=> 'a',
		self::CCC	=> 'b',
		self::DDD	=>  self::AAA
	);
	
	public static function test() {
		self::$foo;
	}
}

foo::test();

The error is only issued when BBB and CCC contains same value.
 [2008-08-25 19:58 UTC] felipe@php.net
I've added two tests (bug45910.phpt, bug45910_2.phpt), the latter segfaults. (5_3 and HEAD)
 [2008-08-26 08:38 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-12-02 10:42 UTC] semnanweb at gmail dot com
same problem on php 5.4.8 apc 1.3.13

http://stackoverflow.com/questions/13272981/cannot-declare-self-referencing-constant/

the bugs for apc. but i need apc. i must restart apache for working sometimes and then same error. restart after some times error and etc ... :(
 [2012-12-12 09:13 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328744
Log: Added test for bug #63669 based on Felipes snippet from #45910
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC