php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #45210 Support for (static) property initilialization is limited
Submitted: 2008-06-08 21:43 UTC Modified: 2008-11-05 07:41 UTC
Votes:4
Avg. Score:3.8 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: jaap dot taal at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jaap dot taal at gmail dot com
New email:
PHP Version: OS:

 

 [2008-06-08 21:43 UTC] jaap dot taal at gmail dot com
Description:
------------
Somehow initializing properties has it's limitations. I think my example should have worked just fine (it would've worked in Java C# and a lot of other language). However, the limitation is there, but I can't find it in the documentation! I think it should be under both Classes and Objects (PHP 4) and Classes and Objects (PHP 5).


Reproduce code:
---------------
<?php
class TestClass {
	public static function somefunc() {
		return 'somevalue';
	}
	public static $someProperty = TestClass::somefunc(); // PARSE ERROR
	protected static $singleton = new TestClass(); // PARSE ERROR
	public $someVar = new TestClass(); // PARSE ERROR
}


Expected result:
----------------
No errors or limitations documented.

Actual result:
--------------
Parse error: syntax error, unexpected '(', expecting ',' or ';' in D:\www\binding\test.php on line 6

Parse error: syntax error, unexpected T_NEW in D:\www\binding\test.php on line 7

Parse error: syntax error, unexpected T_NEW in D:\www\binding\test.php on line 8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-05 07:41 UTC] torben@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I've added a note that static properties are like other static variables in PHP in that they may not be initialized using expressions. 

It would not make sense to document this for PHP 4 classes since in PHP 4 there was no language support for static properties. However, I will look over the static keyword documentation to see whether this could use further clarification there as well.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 13:00:02 2026 UTC