I have a recursive function that looks something like this:
<?php
...recursive function... where value in first line is read, then incremented.
$data=file("data.txt");
print "value is: ".$data[0];
?>
The last line is for testing. There is nothing after that line, no php or html code. The very last line in the file is the ?> .
The strange thing is, I get a value, for example, 10, print out for the last line. So supposedly if I go look at the file, I should find a 10 in the first line. But this is not so. I take a look at it and it is 18.
If the value printed is n, then the value that is in the file is n + 8.
I don't understand how this is possible. There is nothing there after the print... except for the ?>. Nothing should be able to change this value in the file. But when I download the file after running this, it's always n + 8.
I saved another php file with just:
<?php
$data=file("data.txt");
print "value is: ".$data[0];
?>
in it, then ran it, and this correctly reads the value as n + 8. This increment isn't supposed to happen. I have no idea where it's coming from. Surprisingly, the function works absolutely perfectly as expected outside of this peculiar increment that seems to come from nowhere.
very strange error
Moderator: General Moderators
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Use [ php ] tags.
Here's some things you should try:
* Have you turned on error reporting to E_ALL?
* Have you var_dumped all of $data?
* Have you tried accessing the file with other file opening functions (especially ones that read to a string)?
By the way, increment means + 1, so describing a + 8 increase as an increment isn't exactly standard usage.
Here's some things you should try:
* Have you turned on error reporting to E_ALL?
* Have you var_dumped all of $data?
* Have you tried accessing the file with other file opening functions (especially ones that read to a string)?
By the way, increment means + 1, so describing a + 8 increase as an increment isn't exactly standard usage.
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact:
"* Have you turned on error reporting to E_ALL?"
I tried this and I get no errors.
"* Have you var_dumped all of $data? "
I tried this as well. Nothing unusual. Only the first line has a numeric value, as expected.
"* Have you tried accessing the file with other file opening functions (especially ones that read to a string)?"
I tried using fread. The other function, file_get_contents() is somehow unavailable at my server. This reads the same value for the first line as file() .
There is a pattern to this however. If cycle one has a certain variable with a value of 20, cycle2 with 20, cycle3 with 30. Then the value found in the file would be incorrect by var1 + var2 + var3 = 20 + 20 + 30 = 70.
I have no idea what would cause such a mysterious change in the file. Somehow there is a variable that unknown to me is the sum of the variable values of each recursive cycle, then somehow this is added to the value in the file. Even though the last statement checks the file and gives the expected value, there seems to be some ongoing process that corrupts the file either right after the file is checked, or after the script exits.
I tried this and I get no errors.
"* Have you var_dumped all of $data? "
I tried this as well. Nothing unusual. Only the first line has a numeric value, as expected.
"* Have you tried accessing the file with other file opening functions (especially ones that read to a string)?"
I tried using fread. The other function, file_get_contents() is somehow unavailable at my server. This reads the same value for the first line as file() .
There is a pattern to this however. If cycle one has a certain variable with a value of 20, cycle2 with 20, cycle3 with 30. Then the value found in the file would be incorrect by var1 + var2 + var3 = 20 + 20 + 30 = 70.
I have no idea what would cause such a mysterious change in the file. Somehow there is a variable that unknown to me is the sum of the variable values of each recursive cycle, then somehow this is added to the value in the file. Even though the last statement checks the file and gives the expected value, there seems to be some ongoing process that corrupts the file either right after the file is checked, or after the script exits.
-
jaymoore_299
- Forum Contributor
- Posts: 128
- Joined: Wed May 11, 2005 6:40 pm
- Contact: