In PHP, what are some common pitfalls to avoid when working with file input/output operations and data manipulation, especially when dealing with numerical data?

One common pitfall when working with file input/output operations and numerical data manipulation in PHP is not properly handling data types. When reading data from a file, it is important to cast numerical values to the appropriate data type to avoid unexpected behavior. Additionally, when performing calculations or manipulations on numerical data, ensure that the data is properly sanitized and validated to prevent errors or security vulnerabilities.

// Example of properly handling data types when reading numerical data from a file
$file = fopen('data.txt', 'r');
$data = fgets($file);

// Cast the data to the appropriate numerical data type
$number = (int) $data;

fclose($file);