Reputation: 152
I've got a php problem.
I've got a php file that reads data from a .txt file. This works, with this code:
$filename= "deadlines.txt";
$fp = fopen($filename,"r");
$content = fread($fp, filesize($filename));
$rawArray = setRawArray($content);
$epochAndTitleArray = toEpoch($rawArray);
Now, I want to make it so that this stuff is executed every second, not just once at the start. So, I tried to fit it into a function, like this:
$filename= "deadlines.txt";
$fp = 0;
$content = 0;
$rawArray = 0;
$epochAndTitleArray = 0;
function readFile(){
$GLOBALS['fp'] = fopen($GLOBALS['filename'], "r");
$GLOBALS['content'] = fread($GLOBALS['fp'], filesize($GLOBALS['filename']));
$GLOBALS['rawArray'] = setRawArray($GLOBALS['content']);
$GLOBALS['epochAndTitleArray'] = toEpoch($GLOBALS['rawArray']);
}
In this case I'm working with globals, before, I did it without, and also left out the lines before the function itself. This was incorrect I think, so I added the globals.
Now, this doesn't work. It gives me the following error:
Fatal error: Cannot redeclare readFile() in .....on line 28, this line 28 is the line of the closing } at the end of the function.
Can you guys help me in completing this task? Thanks already!
Upvotes: 1
Views: 616
Reputation: 121
Rename 'readFile' to another, readfile() is predefined function 'http://php.net/manual/kr/function.readfile.php'
Upvotes: 1
Reputation: 8278
readfile is a defined function in php , you cannot redeclare it or redeclare any function using the same name .
for more reference about how to declare valid functions in php
PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.
Upvotes: 3