View Issue Details

This bug affects 1 person(s).
 2
IDProjectCategoryView StatusLast Update
19731Bug reportsRemoteControlpublic2024-11-19 18:14
ReporterUllrich Assigned Toc_schmitz  
PrioritynoneSeveritycrash 
Status closedResolutionfixed 
Product Version6.6.x 
Summary19731: null is not a countable type in php 8
Description

If, in below function $query is null, this causes an error in php 8.0.0!

File: ParticipantAttributeName.php

public function editParticipantAttributeValue($data)
{
$query = ParticipantAttribute::model()
->find(
'participant_id = :participant_id AND attribute_id=:attribute_id',
array(':participant_id' => $data['participant_id'],
':attribute_id' => $data['attribute_id'])
);

    if (count($query) == 0) {
        Yii::app()->db->createCommand()
                    ->insert('{{participant_attribute}}', $data);
    } else {
        Yii::app()->db->createCommand()
            ->update(
                '{{participant_attribute}}',
                $data,
                'participant_id = :participant_id2 AND attribute_id = :attribute_id2',
                array(':participant_id2' => $data['participant_id'], ':attribute_id2' => $data['attribute_id'])
            );
    }
}

For reference:
https://www.php.net/manual/en/function.count.php
"
Returns the number of elements in value. Prior to PHP 8.0.0, if the parameter was neither an array nor an object that implements the Countable interface, 1 would be returned, unless value was null, in which case 0 would be returned.
"
php 8.0.0 count() will now throw TypeError on invalid countable types passed to the value parameter.

Steps To Reproduce

I tried to update a user in the cpdb with an extended Remote Control.

If I change:

if (count($query) == 0) {

to

if (is_null($query) ||count($query) == 0) {

everything works as expected.

TagsNo tags attached.
Bug heat2
Complete LimeSurvey version number (& build)6.6.2+240827
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMySql
Server OS (if known)
Webserver software & version (if known)
PHP Version8.3.6

Users monitoring this issue

There are no users monitoring this issue.

Activities

c_schmitz

c_schmitz

2024-09-04 14:15

administrator   ~80896

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=36532

c_schmitz

c_schmitz

2024-09-04 14:15

administrator   ~80897

Thank you!

Related Changesets

LimeSurvey: master b9bdf19e

2024-09-04 16:15

c_schmitz


Details Diff
Fixed issue 19731: Error "null is not a countable type" when updating participant attribute Affected Issues
19731
mod - application/models/ParticipantAttributeName.php Diff File

Issue History

Date Modified Username Field Change
2024-09-04 12:16 Ullrich New Issue
2024-09-04 14:09 c_schmitz Assigned To => c_schmitz
2024-09-04 14:09 c_schmitz Status new => assigned
2024-09-04 14:15 c_schmitz Changeset attached => LimeSurvey master b9bdf19e
2024-09-04 14:15 c_schmitz Note Added: 80896
2024-09-04 14:15 c_schmitz Resolution open => fixed
2024-09-04 14:15 c_schmitz Bug heat 0 => 2
2024-09-04 14:15 c_schmitz Status assigned => resolved
2024-09-04 14:15 c_schmitz Note Added: 80897
2024-11-19 18:14 c_schmitz Status resolved => closed