1.2.1461. Wrong fopen() Mode¶
Wrong file opening for fopen().
fopen() has a few modes, as described in the documentation : ‘r’, ‘r+’, for reading; ‘w’, ‘w+’ for writing; ‘a’, ‘a+’ for appending; ‘x’, ‘x+’ for modifying; ‘c’, ‘c+’ for writing and locking, ‘t’ for text files and windows only. An optional ‘b’ may be used to make the fopen() call more portable and binary safe. Another optional ‘t’ may be used to make the fopen() call process automatically text input : this one should be avoided. Any other values are not understood by PHP.
<?php
// open the file for reading, in binary mode
$fp = fopen('/tmp/php.txt', 'rb');
// New option e in PHP 7.0.16 and 7.1.2 (beware of compatibility)
$fp = fopen('/tmp/php.txt', 'rbe');
// Unknown option x
$fp = fopen('/tmp/php.txt', 'rbx');
?>
1.2.1461.2. Connex PHP features¶
1.2.1461.2.1. Suggestions¶
Check the docs, choose the right opening mode.
1.2.1461.2.2. Specs¶
Short name |
Php/FopenMode |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |