Skip to content

Fix: Prevent implicit float-to-int conversion in applyReplacements()#3

Open
Bebicek wants to merge 2 commits intoevosoftcz:bootstrap_5_lednice_lockfrom
Bebicek:bootstrap_5_lednice_lock
Open

Fix: Prevent implicit float-to-int conversion in applyReplacements()#3
Bebicek wants to merge 2 commits intoevosoftcz:bootstrap_5_lednice_lockfrom
Bebicek:bootstrap_5_lednice_lock

Conversation

@Bebicek
Copy link

@Bebicek Bebicek commented Jun 23, 2025

This pull request addresses a deprecation warning in PHP 8.1+ related to the implicit conversion of float values to integers when used as array keys.

In the applyReplacements() method, the value retrieved from a table row ($value) may be a float. When such a value is used directly as a key in the $this->replacements array, PHP implicitly casts it to an integer (e.g., 178.12 → 178), which can lead to precision loss and unintended behavior.

The fix includes:

  • Checking if $value is a float and, if so, explicitly casting it to a string to preserve precision.
  • Using the resulting value as a safe array key in both isset() and array access.

if ((is_scalar($value) || $value === null) && isset($this->replacements[$value])) {
$key = is_scalar($value) ? (string) $value : $value;

if ((is_scalar($value) || $value === null) && isset($this->replacements[$key])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_float, ne is_scalar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants