|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67880 Class const with calculation.
Submitted: 2014-08-21 12:20 UTC Modified: 2014-11-07 08:07 UTC
Avg. Score:4.2 ± 1.3
Reproduced:3 of 4 (75.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: tux at krageroby dot no Assigned: dmitry (profile)
Status: Closed Package: opcache
PHP Version: 5.6.0 OS: xUbuntu 14.04
Private report: No CVE-ID: None
 [2014-08-21 12:20 UTC] tux at krageroby dot no
Declaring constants that does calculations like in the sample below only works sometimes.

One simple example posted below, I have also some heavier code (I could not reproduce in a small example, but I would think the problem is covered by the other example) that works the first time loaded, and then produce the message: Fatal error: Unsupported operand types in … until the .php file is changed in any way. After the php file is changed, the code runs once before crashing again.

Test script:
class Test
	const ONE = 1;
	const TWO = 2;
	const THREE = self::ONE + self::TWO;

	public function run ()
		return self::THREE;
$test = new Test();
echo $test->run();

Expected result:

Actual result:
Works in cli mode, but apache responds with: 500 internal server error

[Thu Aug 21 13:07:34.283310 2014] [mpm_itk:error] [pid 5184] child died with signal 11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-21 17:25 UTC]
-Status: Open +Status: Feedback
 [2014-08-21 17:25 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read for *NIX and for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

 [2014-08-28 19:59 UTC] tux at krageroby dot no
-Status: Feedback +Status: Open -Package: Unknown/Other Function +Package: opcache -PHP Version: 5.6.0RC4 +PHP Version: 5.6.0
 [2014-08-28 19:59 UTC] tux at krageroby dot no
Tested again without opcache on, and the error is gone. Pretty sure it is opcache related. I have not been successful to create a backtrace.
 [2014-09-01 07:34 UTC] phpwnd at gmail dot com
I see similar behaviour on PHP 5.6.0 but without a crash. The const value becomes UNKNOWN (gettype() returns "unknown type") when accessed from within the class. Accessing it from *outside* the class works correctly. Here's my reproduce code:

class foo
	const one = 1;
	const two = 1 + self::one;
	public static function dump() { var_dump(foo::two); }

Once the script is cached by Opcache, its output becomes:


It doesn't crash, so I have no stack trace to attach.
 [2014-09-04 17:55 UTC]
-Assigned To: +Assigned To: dmitry
 [2014-11-07 08:07 UTC]
-Status: Assigned +Status: Closed
 [2014-11-07 08:07 UTC]
It seems to be fixed already.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Nov 29 20:01:28 2023 UTC