php.net |  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
Votes:4
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tux at krageroby dot no
New email:
PHP Version: OS:

 

 [2014-08-21 12:20 UTC] tux at krageroby dot no
Description:
------------
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:
----------------
3

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-21 17:25 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2014-08-21 17:25 UTC] requinix@php.net
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
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php 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); }
}
var_dump(foo::two);
foo::dump();

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

int(2)
UNKNOWN:0

It doesn't crash, so I have no stack trace to attach.
 [2014-09-04 17:55 UTC] tyrael@php.net
-Assigned To: +Assigned To: dmitry
 [2014-11-07 08:07 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2014-11-07 08:07 UTC] dmitry@php.net
It seems to be fixed already.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 02:03:36 2021 UTC