|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 00:00:02 2025 UTC |
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.