The comments in Net/Random.php indicate that we should expect warnings to come from the fopen of /dev/urandom. In attempt to make that less painful, the php code uses @fopen instead of fopen (ie the error suppression operator) but that does not really work. PHP still generates the warnings, it just does not write them to the output bufer. This causes issues in environments that take warnings seriously (most don't but some do). It seems to me that the best practice in this situation is to wrap the fopen in an if(file_exists('/dev/random'){} That way the fopen would only be attempted in unix like systems that support dev/random and it would not generate warnings on windows systems. There would be no need for the error suppression operator hack or even the comments about warnings in the code. While I don't have a *nix box to test the theory on, it was not difficult to find random.php modules in other packages that use the technique I am proposing. eg:
That does not prove that it works, but it strongly suggests that it does.
Aucun commentaire:
Enregistrer un commentaire