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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
21 + 43 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC