troubleshooting Question

assigning rand() to a variable within a class and declaring it private

Avatar of THEROMPSTER2000
THEROMPSTER2000 asked on
PHP
3 Comments1 Solution275 ViewsLast Modified:
I am tryng to assign rand() to variable $random as a private variable in a php class and i keep getting parse error here, when i assign it the same exact way outside of the declarations its fine.
<?php
 
 
class phplog
{
	private $gMaxFileCount = 2;
  	private $gMaxSize = 200; // 200KB
	private $gFileName = "";
	private $gFilePath = "";
	private $random = rand();
//EXTERNAL Constructor
	function phplog($pFileName,$pFilePath)
	{	
		$this->gFileName = $pFileName;
		$this->gFilePath = $pFilePath;
		exec("dir /o:d /b" . rtrim($pFilePath,"/") . "/" . $pFileName . "????????????.txt /b",$filelist);
 
	//Remove old files
		if(count($filelist) > $this->gMaxFileCount)
		{
			for ($i=1;$i<=count($filelist) - $this->gMaxFileCount;$i++)
			{
				unlink("$filelist[$i]");
			}
		}
 
	//Make a new file if the log is > max size
		if(filesize($pFileName) >= $this->gMaxSize)
  		{
  	  		rename($pFileName, $pFileName.time() . ".txt");
  		}
	}  //phplog
 
//EXTERNAL Writes to the existing log
	function WriteToLog($message)
	{
		file_put_contents($this->gFileName, date("YdmHis",time()) . " " . $random . str_replace("\n","",$message) . "\n", FILE_APPEND);	
		/*
  		$f = fopen($pFileName, "a+") or die("Unable to open log file");
  		fwrite($f, $message);
  		fclose($f);*/
	}
}
?>
ASKER CERTIFIED SOLUTION
themrrobert

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros