php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6881 static variables can't be intialized by function, variable, etc.
Submitted: 2000-09-25 22:06 UTC Modified: 2000-11-08 18:30 UTC
From: simon at comsys dot ntu-kpi dot kiev dot ua Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.2 OS: FreeBSD 4.1-STABLE
Private report: No CVE-ID: None
 [2000-09-25 22:06 UTC] simon at comsys dot ntu-kpi dot kiev dot ua
#!php -q
<?
$a = "abc";
function foo()
{
	global $a;
	static $b = $a;
	static $arr = array($a);
}
?>

I can't ini static variable by another variable or
function. Even more PHP give error while parsing this
code.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-25 22:16 UTC] simon at comsys dot ntu-kpi dot kiev dot ua
#!php -q
<?
$a = "abc";
function foo()
{
	global $a;
	static $b = $a;
	static $arr = array($a);
}
?>

I can't init static variable by another variable or
function. Even more PHP give error while parsing this
code.

 [2000-11-08 18:30 UTC] hholzgra@php.net
you may only use constant values to initialize static variables
in PHP 4, no variables or expressions
this is very similar to initialising class members and happens
for the same reason:

as PHP 4 parses and pre-compiles the whole file before
execution of the PHP code even starts the engine has 
no chance to know the value of a variable or expression
like $a in your example

see also the 'incompatibilities' section unter php.net/version4

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 13:00:01 2026 UTC