|
King of Portal
Join Date: Sep 2005
Posts: 431
Rep Power: 4 
|
Thanks DaWei yeah I meant a variable length argument list. Here's the function that I wrote with it:[PHP]function fluctuate(){
$args = func_get_args();
switch(func_num_args()){
case 1:
if(!is_string($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → <em>filename</em> is not a string", E_USER_ERROR);
if(!file_exists($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Nonexistent file cannot be deleted", E_USER_NOTICE);
if(unlink($args[0])){
return true;
}else{
return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to delete file", E_USER_WARNING);
}
case 4:
if(!is_string($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → <em>filename</em> is not a string", E_USER_ERROR);
if(!is_string($args[1]) || strlen($args[1]) !== 1) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → <em>mode</em> is not a character", E_USER_ERROR);
if(!is_int($args[3])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → <em>mode</em> is not an int", E_USER_ERROR);
$args[1] = strtolower($args[1]);
$ffd = null;
switch($args[1]){
case 'a':
if(!file_exists($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Cannot append to nonexistent file", E_USER_WARNING);
if(!is_writeable($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → File is not writeable", E_USER_WARNING);
if(false === ($ffd = fopen($args[0], "a"))) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to open file", E_USER_WARNING);
break;
case 'w':
if(false === ($ffd = fopen($args[0], "w"))) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to open file", E_USER_WARNING);
if(!file_exists($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Cannot write to nonexistent file", E_USER_WARNING);
if(!is_writeable($args[0])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → File is not writeable", E_USER_WARNING);
break;
default:
return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Illegal mode specified", E_USER_ERROR);
}
if(stream_set_write_buffer($ffd, 0) !== 0) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to buffer stream", E_USER_WARNING);
if(fwrite($ffd, $args[2]) === false) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to write to file", E_USER_WARNING);
if(!fclose($ffd)) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to close file", E_USER_WARNING);
if(!chmod($args[0], $args[3])) return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Unable to change file permissions", E_USER_WARNING);
return true;
default:
return !trigger_error("bool <strong>fluctuate</strong> ( string filename [, string mode [, string string [, int mode]]]) → Incorrect number of arguments passed", E_USER_ERROR);
}
}[/PHP]Who knew file operations could produce so many errors *_* lol
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
|