php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4658 global parameters in class
Submitted: 2000-05-29 11:14 UTC Modified: 2000-05-29 16:00 UTC
From: chedong at yeah dot net Assigned:
Status: Closed Package: Other
PHP Version: 4.0.0 Release OS: freebsd
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: chedong at yeah dot net
New email:
PHP Version: OS:

 

 [2000-05-29 11:14 UTC] chedong at yeah dot net
following code runs properly in php3 but failed at line 3 in php4

<?php
class test {	
	var $test = $PHP_SELF;
	var $test1 = "ok";
	
	function show_test()
	{
		echo $this->test;
		echo $this->test1;
	}
}
$testing = new test;
$testing->show_test();
?>
the error shows:
Parse error: parse error in /home/chedong/public_html/test2.php on line 3
i wrote this for i find some classes i wrote runs properly in php3 but failed when it under php4.............

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-29 16:00 UTC] sterling at cvs dot php dot net
Quoth the incompatibilities list:

  Static variable and class member initializers only accept scalar values (in PHP
  3.0 they accepted any valid expression). The impact should be small, since 
  initializers with anything but a simple static value rarely make sense. 

A workaround is to create a constructor that sets the value of $test:

class test
{
  var $test;
  function test ()
  {
    $this->test = $PHP_SELF;
  }
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 09:01:27 2025 UTC