php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68643 Mathematical expression in class constant initialization causes crash
Submitted: 2014-12-24 06:57 UTC Modified: 2014-12-24 22:27 UTC
From: najamelan at autistici dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.4 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: najamelan at autistici dot org
New email:
PHP Version: OS:

 

 [2014-12-24 06:57 UTC] najamelan at autistici dot org
Description:
------------
I'm sorry, I could only test this on 5.6.2-1 (debian) but it's very fast to verify for someone who has the latest version installed, see script below.

Test script:
---------------
<?php

// php version 5.6.2-1 -> on debian

const BLA = 1;

class Test
{
	
	const BLI = BLA * 5;    // works on cli and crashes the interpreter on cgi (internal server error 500)
	// const BLI = 3   * 5; -> works fine on both cgi and cli but illegal according to the docs
	// https://wiki.php.net/rfc/const_scalar_exprs is said to be implemented in 5.6
	// but neither the language specs nor the documentation reflect this.
	

	function __construct()
	{
		print_r( self::BLI ); // the interpreter only crashes when trying to access the constant
	}
}

new Test();

?>

Expected result:
----------------
1. under no circumstance ever cause internal server 500 error (debugging nightmare)
2. update specs and docs


Actual result:
--------------
500 in apache
nothing in php error log

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-24 20:58 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-12-24 20:58 UTC] aharvey@php.net
This works fine on PHP 5.6.4, including the 5.6.4-1 package in Debian unstable.

This is why we ask reporters to try the latest version. :)
 [2014-12-24 22:27 UTC] najamelan at autistici dot org
Thanks for looking into it. 

I understand your reasoning, but time is precious on this end too and installing and configuring a different version of php and then switching back is quite expensive compared to someone saving a few lines of code into a file and running it. Btw I have a few more php/apache 500 errors to debug ;-( and switching to a newer version of php is not an option if our hoster won't follow suit.

Why not create (or work together with) something like ideone.com to create an online service where users can test code against different versions of php?
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 14:00:02 2026 UTC