Exploring PHP Function Fdiv in PHP 8
This article explores php function fdiv, which is new in PHP 8 and fits nicely alongside functions like fmod() and intdiv(). It adds support for division by zero in floating-point numbers, following the IEEE-754 standard on Floating-Point Arithmetic. This is a welcome addition, since attempts to divide by zero using the division operator currently trigger a warning in existing code that will eventually escalate to a DivisionByZeroError exception in the future.
Other notable additions include a refactored get_debug_type() function that always returns the true native type of variables, i.e., int rather than integer or float rather than float. This makes it easier to test code for correctness, and enables code that relies on variables to have self-documenting names such as $user_id rather than simply $id.
There is also a new function called __str_starts_with() that returns a bool indicating whether a given string starts with the string specified in its argument. This is useful for avoiding leaking of sensitive parameter values that might otherwise be exposed by an exception stack trace. Finally, there is a new __callStatic() function that allows you to specify the visibility of method parameters (public or private). This is useful when using magic methods in conjunction with an object-oriented framework such as Object-Oriented PHP.