I have a file containing:
<?php
return '2000-01-01 00:00:00';
?>
and I have this code:
<?php
$oldValue = require 'file.php';
$now = new DateTime();
$handle = fopen('file.php', "w");
fputs($handle, "<?php
return '" . $now->format('Y-m-d H:i:s') . "';");
fclose($handle);
$newValue = require 'file.php';
echo "Old value: $oldValue ";
echo "New value: $newValue ";
?>
The output with PHP 5.3 is:
Old value: 2000-01-01 00:00:00 New value: 2018-03-28 10:33:12
The output with PHP 7.1 is:
Old value: 2000-01-01 00:00:00 New value: 2000-01-01 00:00:00
In the two cases, the string in the file changes.
Can some one help me to update the new value with PHP 7.1?
Note: it's not the real problem. It's just an abstraction of the problem to make things more simple and comprehensible. So please, no lessons of PHP best practices. I just like to get a good response to my question.
Thanks :)