From e63fd5dde471e1bd9e6d5b360d78bd6ab6fd8d1d Mon Sep 17 00:00:00 2001 From: lestcape Date: Tue, 18 May 2021 15:17:28 -0500 Subject: [PATCH] The sav ValueLabels are conceived to be once per several variables (indexes), but the library handle it one per variable, what duplicate it. So, what we have is just a list of the current variables where only the last one (the current) that create the valuelabel, is related with it. So, find if we need to convert the string to double there, because the indexes are pointing to the place where the variable will be stored, not to the variable itself. --- src/Sav/Record/ValueLabel.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Sav/Record/ValueLabel.php b/src/Sav/Record/ValueLabel.php index f58d6c3..d2dad5d 100644 --- a/src/Sav/Record/ValueLabel.php +++ b/src/Sav/Record/ValueLabel.php @@ -89,12 +89,8 @@ public function read(Buffer $buffer) public function write(Buffer $buffer) { - $convertToDouble = false; - $varIndex = reset($this->indexes); - if (false !== $varIndex && isset($this->variables[$varIndex - 1])) { - $varWidth = $this->variables[$varIndex - 1]->width; - $convertToDouble = $varWidth > 0; - } + $var = (count($this->variables) > 0) ? $this->variables[count($this->variables) - 1] : null; + $convertToDouble = (isset($var) && ($var->width > 0)); // Value label record. $buffer->writeInt(self::TYPE);