Using arrays values as function defaults?

I am trying to write a quick, simple function to write string content into a file I designate.

I wanted to use use the $_SERVER[‘DOCUMENT_ROOT’] as a default parameter.

Here is the code:


<?php
function write_to_file($content, $filename, $file_path = $_SERVER['DOCUMENT_ROOT'], $action_mode = 'a')
	{
		$fp = fopen($file_path.'/'.$filename , $action_mode); 
		fputs($fp, $content);
		fclose($fp);
		

	}

$content = 'test content';

$filename = 'test.txt';

write_to_file($content ,$filename );
?>

This produces a error:


[24-May-2010 17:18:43] PHP Parse error:  syntax error, unexpected T_VARIABLE in /home/username/public_html/test.php on line 2

It seems the use of $_SERVER[‘DOCUMENT_ROOT’] is causing the error.

Is there a way to use array values as default values in function parameters?

You can’t use a variable as a default argument in a function


function write_to_file($content, $filename, $file_path = '', $action_mode = 'a')
{
    if($file_path == '') $file_path = $_SERVER['DOCUMENT_ROOT'];
    $fp = fopen($file_path.'/'.$filename , $action_mode); 
    fputs($fp, $content);
    fclose($fp);
}