Skip to content

Commit

Permalink
Fixed #19217: PHP8 Error Type NULL (#3666)
Browse files Browse the repository at this point in the history
* Fixed: 19217 Update Survey.php

$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? '');
change to
$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? []);
In PHP 7 it is a warning
in PHP 8 it's a 500! parameter key() must be an array!!

* Fixed 10217: Update common_helper.php

$aSavedExtraTokenFields = Survey::model()->findByPk($surveyid)->tokenAttributes;
change to:
$aSavedExtraTokenFields = Survey::model()->findByPk($surveyid)->tokenAttributes ?? [];
In PHP 7 it is a warning
in PHP 8 it's a 500! $aSavedExtraTokenFields is not allowed to be NULL anymore! in function array_intersect_key()!

* Update common_helper.php

Corrected code line 2946

* #19217: Update Survey.php

revert back to from ?? [] to ?? '' on line 667

* #19217: Update Survey.php

Extra check on first element of array
If it is not an array set array to NULL

* #19217: Update Survey.php

Final edit after line 667:
Check on array after reset(array)

* #19217: Update Survey.php

And some missing spaces...
this one should pass!!!
  • Loading branch information
BertHankes committed Jan 31, 2024
1 parent e78bedb commit a908e85
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion application/helpers/common_helper.php
Expand Up @@ -2943,7 +2943,7 @@ function getTokenFieldsAndNames($surveyid, $bOnlyAttributes = false)
);

$aExtraTokenFields = getAttributeFieldNames($surveyid);
$aSavedExtraTokenFields = Survey::model()->findByPk($surveyid)->tokenAttributes;
$aSavedExtraTokenFields = Survey::model()->findByPk($surveyid)->tokenAttributes ?? [];

// Drop all fields that are in the saved field description but not in the table definition
$aSavedExtraTokenFields = array_intersect_key($aSavedExtraTokenFields, array_flip($aExtraTokenFields));
Expand Down
4 changes: 3 additions & 1 deletion application/models/Survey.php
Expand Up @@ -665,7 +665,9 @@ public function getAllLanguages()
public function getTokenAttributes()
{
$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? '');

if (!is_array(reset($attdescriptiondata))) {
$attdescriptiondata = null;
}
// Catches malformed data
if ($attdescriptiondata && strpos((string) key(reset($attdescriptiondata)), 'attribute_') === false) {
// don't know why yet but this breaks normal tokenAttributes functionning
Expand Down

0 comments on commit a908e85

Please sign in to comment.