View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
19217Bug reportsSurvey editingpublic2024-06-25 17:23
Reporterasshank Assigned Togabrieljenik  
PrioritynoneSeverityblock 
Status closedResolutionfixed 
Product Version6.3.x 
Summary19217: Error under php 8.x
Description

The attached survey gives an error under php 8.x. It runs OK on php 7.4.

error: 500: Internal Server Error key(): Argument #1 ($array) must be of type array, string given

Steps To Reproduce

Steps to reproduce

import the lss and try to view a group or question in the management environment.

Expected result

on 7.4 this works as expected, not on php 8.x

Actual result on php 8.x

error: 500: Internal Server Error key(): Argument #1 ($array) must be of type array, string given

TagsNo tags attached.
Attached Files
debug.png (118,821 bytes)
Bug heat10
Complete LimeSurvey version number (& build)6.3.2+231031
I will donate to the project if issue is resolvedNo
Browseredge
Database type & versionmysql 5.5.68-1.el75.5.68-1.el7
Server OS (if known)CentOS Linux 7.9.2009 (Core)
Webserver software & version (if known)Apache
PHP Version7.4 vs 8.x

Users monitoring this issue

There are no users monitoring this issue.

Activities

ollehar

ollehar

2023-11-02 15:39

administrator   ~78215

Can you enable debug = 2 in application/config/config.php and try again, please? Paste the complete error message here.

asshank

asshank

2023-11-06 12:27

reporter   ~78279

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHP warning</title>

<style type="text/css">
/<![CDATA[/
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent;margin:0;padding:0;}
body{line-height:1;}
ol,ul{list-style:none;}
blockquote,q{quotes:none;}
blockquote:before,blockquote:after,q:before,q:after{content:none;}
:focus{outline:0;}
ins{text-decoration:none;}
del{text-decoration:line-through;}
table{border-collapse:collapse;border-spacing:0;}

body {
font: normal 9pt "Verdana";
color: #000;
background: #fff;
}

h1 {
font: normal 18pt "Verdana";
color: #f00;
margin-bottom: .5em;
}

h2 {
font: normal 14pt "Verdana";
color: #800000;
margin-bottom: .5em;
}

h3 {
font: bold 11pt "Verdana";
}

pre {
font: normal 11pt Menlo, Consolas, "Lucida Console", Monospace;
}

pre span.error {
display: block;
background: #fce3e3;
}

pre span.ln {
color: #999;
padding-right: 0.5em;
border-right: 1px solid #ccc;
}

pre span.error-ln {
font-weight: bold;
}

.container {
margin: 1em 4em;
}

.version {
color: gray;
font-size: 8pt;
border-top: 1px solid #aaa;
padding-top: 1em;
margin-bottom: 1em;
}

.message {
color: #000;
padding: 1em;
font-size: 11pt;
background: #f3f3f3;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
margin-bottom: 1em;
line-height: 160%;
}

.source {
margin-bottom: 1em;
}

.code pre {
background-color: #ffe;
margin: 0.5em 0;
padding: 0.5em;
line-height: 125%;
border: 1px solid #eee;
}

.source .file {
margin-bottom: 1em;
font-weight: bold;
}

.traces {
margin: 2em 0;
}

.trace {
margin: 0.5em 0;
padding: 0.5em;
}

.trace.app {
border: 1px dashed #c00;
}

.trace .number {
text-align: right;
width: 2em;
padding: 0.5em;
}

.trace .content {
padding: 0.5em;
}

.trace .plus,
.trace .minus {
display:inline;
vertical-align:middle;
text-align:center;
border:1px solid #000;
color:#000;
font-size:10px;
line-height:10px;
margin:0;
padding:0 1px;
width:10px;
height:10px;
}

.trace.collapsed .minus,
.trace.expanded .plus,
.trace.collapsed pre {
display: none;
}

.trace-file {
cursor: pointer;
padding: 0.2em;
}

.trace-file:hover {
background: #f0ffff;
}
/]]>/
</style>
</head>

<body>
<div class="container">
<h1>PHP warning</h1>

<p class="message">
    key() expects parameter 1 to be array, string given </p>

<div class="source">
    <p class="file">/var/www/vhosts/assendelfthankes.nl/lime6/application/models/Survey.php(676)</p>
    <div class="code"><pre><span class="ln">664</span> 

<span class="ln">665</span> /*
<span class="ln">666</span>
Returns the additional token attributes
<span class="ln">667</span>
<span class="ln">668</span>
@access public
<span class="ln">669</span> @return array
<span class="ln">670</span>
/
<span class="ln">671</span> public function getTokenAttributes()
<span class="ln">672</span> {
<span class="ln">673</span> $attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? '');
<span class="ln">674</span>
<span class="ln">675</span> // Catches malformed data
<span class="error"><span class="ln error-ln">676</span> if ($attdescriptiondata && strpos((string) key(reset($attdescriptiondata)), 'attribute_') === false) {
</span><span class="ln">677</span> // don't know why yet but this breaks normal tokenAttributes functionning
<span class="ln">678</span> //$attdescriptiondata=array_flip(GetAttributeFieldNames($this->sid));
<span class="ln">679</span> } elseif (is_null($attdescriptiondata)) {
<span class="ln">680</span> $attdescriptiondata = array();
<span class="ln">681</span> }
<span class="ln">682</span> // Legacy records support
<span class="ln">683</span> if ($attdescriptiondata === false) {
<span class="ln">684</span> $attdescriptiondata = explode("\n", $this->attributedescriptions);
<span class="ln">685</span> $fields = array();
<span class="ln">686</span> $languagesettings = array();
<span class="ln">687</span> foreach ($attdescriptiondata as $attdescription) {
<span class="ln">688</span> if (trim($attdescription) != '') {
</div> </div>

<div class="traces">
    <h2>Stack Trace</h2>
            <table style="width:100%;">
                    <tr class="trace app expanded">
        <td class="number">
            #0          </td>
        <td class="content">
            <div class="trace-file">
                                        <div class="plus">+</div>
                    <div class="minus">–</div>
                                    &nbsp;/var/www/vhosts/assendelfthankes.nl/lime6/application/models/Survey.php(676): <strong>key</strong>(&quot;5&quot;)             </div>

            <div class="code"><pre><span class="ln">671</span>     public function getTokenAttributes()

<span class="ln">672</span> {
<span class="ln">673</span> $attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? '');
<span class="ln">674</span>
<span class="ln">675</span> // Catches malformed data
<span class="error"><span class="ln error-ln">676</span> if ($attdescriptiondata && strpos((string) key(reset($attdescriptiondata)), 'attribute_') === false) {
</span><span class="ln">677</span> // don't know why yet but this breaks normal tokenAttributes functionning
<span class="ln">678</span> //$attdescriptiondata=array_flip(GetAttributeFieldNames($this->sid));
<span class="ln">679</span> } elseif (is_null($attdescriptiondata)) {
<span class="ln">680</span> $attdescriptiondata = array();
<span class="ln">681</span> }
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#1 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/base/CComponent.php(111): Survey->getTokenAttributes() </div>

            <div class="code"><pre><span class="ln">106</span>      */

<span class="ln">107</span> public function __get($name)
<span class="ln">108</span> {
<span class="ln">109</span> $getter='get'.$name;
<span class="ln">110</span> if(method_exists($this,$getter))
<span class="error"><span class="ln error-ln">111</span> return $this->$getter();
</span><span class="ln">112</span> elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name))
<span class="ln">113</span> {
<span class="ln">114</span> // duplicating getEventHandlers() here for performance
<span class="ln">115</span> $name=strtolower($name);
<span class="ln">116</span> if(!isset($this->_e[$name]))
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#2 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(145): CComponent->__get("tokenAttributes") </div>

            <div class="code"><pre><span class="ln">140</span>         elseif(isset($this-&gt;_related[$name]))

<span class="ln">141</span> return $this->_related[$name];
<span class="ln">142</span> elseif(isset($this->getMetaData()->relations[$name]))
<span class="ln">143</span> return $this->getRelated($name);
<span class="ln">144</span> else
<span class="error"><span class="ln error-ln">145</span> return parent::__get($name);
</span><span class="ln">146</span> }
<span class="ln">147</span>
<span class="ln">148</span> /*
<span class="ln">149</span>
PHP setter magic method.
<span class="ln">150</span> * This method is overridden so that AR attributes can be accessed like properties.
</div> </td>
</tr>
<tr class="trace app expanded">
<td class="number">
#3 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/application/helpers/common_helper.php(797): CActiveRecord->__get("tokenAttributes") </div>

            <div class="code"><pre><span class="ln">792</span>             $thissurvey[&#039;email_remind&#039;] = $thissurvey[&#039;surveyls_email_remind&#039;];

<span class="ln">793</span> $thissurvey['email_confirm_subj'] = $thissurvey['surveyls_email_confirm_subj'];
<span class="ln">794</span> $thissurvey['email_confirm'] = $thissurvey['surveyls_email_confirm'];
<span class="ln">795</span> $thissurvey['email_register_subj'] = $thissurvey['surveyls_email_register_subj'];
<span class="ln">796</span> $thissurvey['email_register'] = $thissurvey['surveyls_email_register'];
<span class="error"><span class="ln error-ln">797</span> $thissurvey['attributedescriptions'] = $result->survey->tokenAttributes;
</span><span class="ln">798</span> $thissurvey['attributecaptions'] = $result->attributeCaptions;
<span class="ln">799</span> $thissurvey['googleanalyticsapikey'] = $oSurvey->getGoogleanalyticsapikey();
<span class="ln">800</span> if (!isset($thissurvey['adminname'])) {
<span class="ln">801</span> $thissurvey['adminname'] = Yii::app()->getConfig('siteadminemail');
<span class="ln">802</span> }
</div> </td>
</tr>
<tr class="trace app expanded">
<td class="number">
#4 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/application/helpers/expressions/em_manager_helper.php(4522): getSurveyInfo(553562) </div>

            <div class="code"><pre><span class="ln">4517</span>         $LEM-&gt;allOnOnePage = $allOnOnePage;

<span class="ln">4518</span> $LEM->processedRelevance = false;
<span class="ln">4519</span> $LEM->surveyOptions['hyperlinkSyntaxHighlighting'] = true; // this will be temporary - should be reset in running survey
<span class="ln">4520</span> $LEM->qid2exclusiveAuto = [];
<span class="ln">4521</span> self::resetTempVars();
<span class="error"><span class="ln error-ln">4522</span> $surveyinfo = (isset($LEM->sid) ? getSurveyInfo($LEM->sid) : null);
</span><span class="ln">4523</span> if (isset($surveyinfo['assessments']) && $surveyinfo['assessments'] == 'Y') {
<span class="ln">4524</span> $LEM->surveyOptions['assessments'] = true;
<span class="ln">4525</span> }
<span class="ln">4526</span> // $LEM->runtimeTimings[] = array(METHOD,(microtime(true) - $now));
<span class="ln">4527</span>
</div> </td>
</tr>
<tr class="trace app collapsed">
<td class="number">
#5 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/application/controllers/SurveyAdministrationController.php(134): LimeExpressionManager::StartProcessingPage(false, true) </div>

            <div class="code"><pre><span class="ln">129</span> 

<span class="ln">130</span> // Reinit LEMlang and LEMsid: ensure LEMlang are set to default lang, surveyid are set to this survey id
<span class="ln">131</span> // Ensure Last GetLastPrettyPrintExpression get info from this sid and default lang
<span class="ln">132</span> LimeExpressionManager::SetEMLanguage($baselang);
<span class="ln">133</span> LimeExpressionManager::SetSurveyId($iSurveyID);
<span class="error"><span class="ln error-ln">134</span> LimeExpressionManager::StartProcessingPage(false, true);
</span><span class="ln">135</span>
<span class="ln">136</span> //breadcrumb
<span class="ln">137</span> if (isset($survey->currentLanguageSettings) && isset($survey->currentLanguageSettings->surveyls_title)) {
<span class="ln">138</span> $aData['title_bar']['title'] =
<span class="ln">139</span> $survey->currentLanguageSettings->surveyls_title . " (" . gT("ID") . ":" . $iSurveyID . ")";
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#6 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/web/actions/CInlineAction.php(49): SurveyAdministrationController->actionView() </div>

            <div class="code"><pre><span class="ln">44</span>         $controller=$this-&gt;getController();

<span class="ln">45</span> $method=new ReflectionMethod($controller, $methodName);
<span class="ln">46</span> if($method->getNumberOfParameters()>0)
<span class="ln">47</span> return $this->runWithParamsInternal($controller, $method, $params);
<span class="ln">48</span>
<span class="error"><span class="ln error-ln">49</span> $controller->$methodName();
</span><span class="ln">50</span> return true;
<span class="ln">51</span> }
<span class="ln">52</span> }
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#7 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/web/CController.php(308): CInlineAction->runWithParams(array("iSurveyID" => "553562")) </div>

            <div class="code"><pre><span class="ln">303</span>     {

<span class="ln">304</span> $priorAction=$this->_action;
<span class="ln">305</span> $this->_action=$action;
<span class="ln">306</span> if($this->beforeAction($action))
<span class="ln">307</span> {
<span class="error"><span class="ln error-ln">308</span> if($action->runWithParams($this->getActionParams())===false)
</span><span class="ln">309</span> $this->invalidActionParams($action);
<span class="ln">310</span> else
<span class="ln">311</span> $this->afterAction($action);
<span class="ln">312</span> }
<span class="ln">313</span> $this->_action=$priorAction;
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#8 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/web/CController.php(286): CController->runAction(CInlineAction) </div>

            <div class="code"><pre><span class="ln">281</span>      * @see runAction

<span class="ln">282</span> */
<span class="ln">283</span> public function runActionWithFilters($action,$filters)
<span class="ln">284</span> {
<span class="ln">285</span> if(empty($filters))
<span class="error"><span class="ln error-ln">286</span> $this->runAction($action);
</span><span class="ln">287</span> else
<span class="ln">288</span> {
<span class="ln">289</span> $priorAction=$this->_action;
<span class="ln">290</span> $this->_action=$action;
<span class="ln">291</span> CFilterChain::create($this,$action,$filters)->run();
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#9 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array()) </div>

            <div class="code"><pre><span class="ln">260</span>         {

<span class="ln">261</span> if(($parent=$this->getModule())===null)
<span class="ln">262</span> $parent=Yii::app();
<span class="ln">263</span> if($parent->beforeControllerAction($this,$action))
<span class="ln">264</span> {
<span class="error"><span class="ln error-ln">265</span> $this->runActionWithFilters($action,$this->filters());
</span><span class="ln">266</span> $parent->afterControllerAction($this,$action);
<span class="ln">267</span> }
<span class="ln">268</span> }
<span class="ln">269</span> else
<span class="ln">270</span> $this->missingAction($actionID);
</div> </td>
</tr>
<tr class="trace app collapsed">
<td class="number">
#10 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/application/controllers/LSBaseController.php(145): CController->run("view") </div>

            <div class="code"><pre><span class="ln">140</span>                     $this-&gt;redirect(array(&#039;/admin/authentication/sa/login&#039;));

<span class="ln">141</span> }
<span class="ln">142</span> }
<span class="ln">143</span> }
<span class="ln">144</span>
<span class="error"><span class="ln error-ln">145</span> parent::run($action);
</span><span class="ln">146</span> }
<span class="ln">147</span>
<span class="ln">148</span> /*
<span class="ln">149</span>
Load and set session vars
<span class="ln">150</span> *
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#11 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/web/CWebApplication.php(282): LSBaseController->run("view") </div>

            <div class="code"><pre><span class="ln">277</span>         {

<span class="ln">278</span> list($controller,$actionID)=$ca;
<span class="ln">279</span> $oldController=$this->_controller;
<span class="ln">280</span> $this->_controller=$controller;
<span class="ln">281</span> $controller->init();
<span class="error"><span class="ln error-ln">282</span> $controller->run($actionID);
</span><span class="ln">283</span> $this->_controller=$oldController;
<span class="ln">284</span> }
<span class="ln">285</span> else
<span class="ln">286</span> throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',
<span class="ln">287</span> array('{route}'=>$route===''?$this->defaultController:$route)));
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#12 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/web/CWebApplication.php(141): CWebApplication->runController("surveyAdministration/view") </div>

            <div class="code"><pre><span class="ln">136</span>             foreach(array_splice($this-&gt;catchAllRequest,1) as $name=&gt;$value)

<span class="ln">137</span> $_GET[$name]=$value;
<span class="ln">138</span> }
<span class="ln">139</span> else
<span class="ln">140</span> $route=$this->getUrlManager()->parseUrl($this->getRequest());
<span class="error"><span class="ln error-ln">141</span> $this->runController($route);
</span><span class="ln">142</span> }
<span class="ln">143</span>
<span class="ln">144</span> /*
<span class="ln">145</span>
Registers the core application components.
<span class="ln">146</span> * This method overrides the parent implementation by registering additional core components.
</div> </td>
</tr>
<tr class="trace core collapsed">
<td class="number">
#13 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/vendor/yiisoft/yii/framework/base/CApplication.php(185): CWebApplication->processRequest() </div>

            <div class="code"><pre><span class="ln">180</span>     public function run()

<span class="ln">181</span> {
<span class="ln">182</span> if($this->hasEventHandler('onBeginRequest'))
<span class="ln">183</span> $this->onBeginRequest(new CEvent($this));
<span class="ln">184</span> register_shutdown_function(array($this,'end'),0,false);
<span class="error"><span class="ln error-ln">185</span> $this->processRequest();
</span><span class="ln">186</span> if($this->hasEventHandler('onEndRequest'))
<span class="ln">187</span> $this->onEndRequest(new CEvent($this));
<span class="ln">188</span> }
<span class="ln">189</span>
<span class="ln">190</span> /**
</div> </td>
</tr>
<tr class="trace app collapsed">
<td class="number">
#14 </td>
<td class="content">
<div class="trace-file">
<div class="plus">+</div>
<div class="minus">–</div>
 /var/www/vhosts/assendelfthankes.nl/lime6/index.php(161): CApplication->run() </div>

            <div class="code"><pre><span class="ln">156</span> require_once APPPATH . &#039;core/LSYii_Application&#039; . EXT;

<span class="ln">157</span>
<span class="ln">158</span> $config = require_once(APPPATH . 'config/internal' . EXT);
<span class="ln">159</span>
<span class="ln">160</span> Yii::$enableIncludePath = false;
<span class="error"><span class="ln error-ln">161</span> Yii::createApplication('LSYii_Application', $config)->run();
</span><span class="ln">162</span>
<span class="ln">163</span> / End of file index.php /
<span class="ln">164</span> / Location: ./index.php /
</div> </td>
</tr>
</table>
</div>

<div class="version">
    2023-11-06 12:23:53 Apache <a href="https://www.yiiframework.com/">Yii Framework</a>/1.1.28 </div>

</div>

<script type="text/javascript">
/<![CDATA[/
var traceReg = new RegExp("(^|\s)trace-file(\s|$)");
var collapsedReg = new RegExp("(^|\s)collapsed(\s|$)");

var e = document.getElementsByTagName("div");
for(var j=0,len=e.length;j<len;j++){
if(traceReg.test(e[j].className)){
e[j].onclick = function(){
var trace = this.parentNode.parentNode;
if(collapsedReg.test(trace.className))
trace.className = trace.className.replace("collapsed", "expanded");
else
trace.className = trace.className.replace("expanded", "collapsed");
}
}
}
/]]>/
</script>

</body>
</html>

asshank

asshank

2023-12-15 09:06

reporter   ~78998

It happens when an lime 4 SID is imported also.
For us... Lime6 on PHP 8.0 and higher is just not working due to this error...
I'm on LimeSurvey Community Edition Versie 6.3.9+231211 now!
I analysed that application/models/Survey.php
public function getTokenAttributes()
is the problem showing the KEY() error. It always is 500 during this function!
And reading the comments in source tells me '// don't know why yet but this breaks normal tokenAttributes functionning' Strange behaviour detected!?

asshank

asshank

2023-12-15 11:09

reporter   ~79003

When debug=1 of 2 the same debug pops up on PHP 7.4!
But PHP 7.4 and debug =0: Lime6 does not crash!
On PHP 8 it does crash when debug=0!!! So the problem is there a long time.. hence the comments in the code!?
I wil try to dig in this further!

asshank

asshank

2023-12-15 11:28

reporter   ~79004

Got it!!!!

application/helpers/common_helper.php
line 2946

$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()!

asshank

asshank

2023-12-15 11:32

reporter   ~79005

But first:
application/models/Survey.php on line 667:

$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!!

asshank

asshank

2023-12-15 14:00

reporter   ~79012

I'm a bit reluctant to pull in github...But I just did! Hope I did this the right way!

asshank

asshank

2023-12-17 13:07

reporter   ~79019

Further assessment of the problem.
The 500 occurs when a SID without Tokens is run, imported or edited!
And that is consistent with both Token function issues... No Tokens then array of tokens should be an empty array ([])
I think this is the root of the problem!

We have another system running on PHP 8.2 without problemns but all the SID's are Tokenized!!

gabrieljenik

gabrieljenik

2023-12-29 20:50

manager   ~79077

How does it handle 8.0?

asshank

asshank

2023-12-31 10:25

reporter   ~79078

PHP 8.0.30

500: Internal Server Error key(): Argument #1 ($array) must be of type array, string given
Just by opening (as admin) a SID without tokens!
... index.php/surveyAdministration/view?iSurveyID=461627

gabrieljenik

gabrieljenik

2024-01-02 17:33

manager   ~79083

Can you include a pdf print (or snapshot) of the stacktrace of the error?

asshank

asshank

2024-01-02 17:55

reporter   ~79084

Hi Gabriel,

see https://bugs.limesurvey.org/view_user_page.php?id=48049
debug.png

asshank

asshank

2024-01-02 21:49

reporter   ~79085

debug.png: https://bugs.limesurvey.org/file_download.php?file_id=17626&type=bug

asshank

asshank

2024-01-03 09:59

reporter   ~79087

I made a PR
https://github.com/LimeSurvey/LimeSurvey/compare/master...BertHankes:LimeSurvey:master

asshank

asshank

2024-01-03 11:59

reporter   ~79088

I'm always struggeling with GitHub

but
in application/helpers/common_helper.php on line 2946:
$aSavedExtraTokenFields = Survey::model()->findByPk($surveyid)->tokenAttributes ?? [];

and in application/models/Survey.php on line 667:
$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? []);

Has resolved the issue!

asshank

asshank

2024-01-03 13:14

reporter   ~79090

made another commit.. so Github will pass the code!

reverted survey.php to
$attdescriptiondata = decodeTokenAttributes($this->attributedescriptions ?? '');

but then the bug is there again!

so somehow $attdescriptiondata is of the wrong type here! Github checks is not detecting this!
That's way it is hard to debug (also with lime debug=2)!

So again (very strange): on line 670 of survey.php:

key(reset($attdescriptiondata))
is clearly an error here!
$attdescriptiondata is an array!
reset($attdescriptiondata) will reset the pointer in the array en returns the first element!
In my case the element is a string/numeric not an array!
so key() will die in >8.0 because the result of reset($attdescriptiondata) is not an array!!

I guess when SID is tokenized the first element of the array is also an array!!!

So I made this correction in GitHub...
Hopefully this wil pass and the fix is legit!

so inserted after line 667 in models/Survey.php (after a couple of space missing issues) :
if (!is_array(reset($attdescriptiondata))) {
$attdescriptiondata = null;
}
And for the sake of it.. in my case with this fix the issue is fixed!

asshank

asshank

2024-01-23 19:45

reporter   ~79302

What do I have to do to commit my changes?
Someone can pick this up?

ollehar

ollehar

2024-01-24 09:50

administrator   ~79304

You can ping @tibor.pacalat about it and he will have a look when he has time.

asshank

asshank

2024-01-24 10:40

reporter   ~79306

@tibor.pacalat
mind have a look at my PR for this problem (solved)
https://github.com/LimeSurvey/LimeSurvey/compare/master...BertHankes:LimeSurvey:master

asshank

asshank

2024-01-31 09:21

reporter   ~79363

@gabrieljenik @tibor.pacalat
Please.. check out
https://github.com/LimeSurvey/LimeSurvey/compare/master...BertHankes:LimeSurvey:master

For us: LIme without tokens on PHP 8 is error 500

tibor.pacalat

tibor.pacalat

2024-01-31 14:32

administrator   ~79364

@asshank I tested it and it fixes the issue, however Kevin did the code review and left you a message. Please take a look when you have time.

asshank

asshank

2024-01-31 14:55

reporter   ~79366

I replied to Kevin:
kevin-foster-uk 25 minutes ago
Why do you call reset() here?

Contributor
Author
@BertHankes BertHankes 1 minute ago
Because the reset() function is used by the native code on line 670:
if ($attdescriptiondata && strpos((string) key(reset($attdescriptiondata)), 'attribute_') === false)

And if reset() is not returning an array (in this case a NULL).. key() gives a 500
In trying to debug it is/was very hard to get to this state... strpos(key(reset($attdescriptiondata))... has 3 functions in one line.

The reset(array) is returning null because there are no tokens!

From PHP help:
reset() rewinds array's internal pointer to the first element and returns the value of the first array element.
The value returned by reset(), when not having tokens, is null!

And in PHP<8 it was all good.. but now it is strict! Key(NULL) is not allowed anymore and results in 500

guest

guest

2024-01-31 17:59

viewer   ~79381

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

asshank

asshank

2024-01-31 19:05

reporter   ~79382

@gabrieljenik @tibor.pacalat
Come to think off it... the 5.x branch has the same bug!
Who is going to do that branch?

tibor.pacalat

tibor.pacalat

2024-02-01 10:05

administrator   ~79383

@asshank can you do it for 5.x as well? Thank you in advance :) Just post a PR link here and I'll take care of code review and merging it in.

asshank

asshank

2024-02-01 12:45

reporter   ~79389

@gabrieljenik @tibor.pacalat
I'm not allowed tot make a PR for the 5.x branch

Pull request creation failed. Validation failed: must be a collaborator

tibor.pacalat

tibor.pacalat

2024-02-02 12:24

administrator   ~79393

@gabrieljenik can you take care of this? Create PR with the same fix for 5.x

gabrieljenik

gabrieljenik

2024-02-15 21:23

manager   ~79532

v5: https://github.com/LimeSurvey/LimeSurvey/pull/3743

guest

guest

2024-02-26 13:55

viewer   ~79641

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

Related Changesets

LimeSurvey: master a908e85d

2024-01-31 18:59

Bert Hankes

Committer: GitHub


Details Diff
Fixed 19217: PHP8 Error Type NULL (#3666)

* 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!!!
Affected Issues
19217
mod - application/helpers/common_helper.php Diff File
mod - application/models/Survey.php Diff File

LimeSurvey: 5.x c22d893c

2024-02-26 14:45

Gabriel Jenik

Committer: GitHub


Details Diff
Fixed 19217: PHP8 Error Type NULL (03743) Affected Issues
19217
mod - application/helpers/common_helper.php Diff File
mod - application/models/Survey.php Diff File

Issue History

Date Modified Username Field Change
2023-11-02 13:35 asshank New Issue
2023-11-02 13:35 asshank File Added: debug.png
2023-11-02 13:35 asshank File Added: limesurvey_survey_553562 (2).lss
2023-11-02 15:39 ollehar Assigned To => ollehar
2023-11-02 15:39 ollehar Status new => feedback
2023-11-02 15:39 ollehar Note Added: 78215
2023-11-02 15:39 ollehar Bug heat 0 => 2
2023-11-06 12:27 asshank Note Added: 78279
2023-11-06 12:27 asshank Bug heat 2 => 4
2023-11-06 12:27 asshank Status feedback => assigned
2023-12-15 09:06 asshank Note Added: 78998
2023-12-15 11:09 asshank Note Added: 79003
2023-12-15 11:28 asshank Note Added: 79004
2023-12-15 11:32 asshank Note Added: 79005
2023-12-15 14:00 asshank Note Added: 79012
2023-12-17 13:07 asshank Note Added: 79019
2023-12-29 20:50 gabrieljenik Note Added: 79077
2023-12-29 20:50 gabrieljenik Bug heat 4 => 6
2023-12-31 10:25 asshank Note Added: 79078
2024-01-02 16:35 gabrieljenik Assigned To ollehar => gabrieljenik
2024-01-02 17:33 gabrieljenik Note Added: 79083
2024-01-02 17:55 asshank Note Added: 79084
2024-01-02 21:49 asshank Note Added: 79085
2024-01-03 09:59 asshank Note Added: 79087
2024-01-03 11:59 asshank Note Added: 79088
2024-01-03 13:14 asshank Note Added: 79090
2024-01-23 19:45 asshank Note Added: 79302
2024-01-24 09:50 ollehar Note Added: 79304
2024-01-24 10:40 asshank Note Added: 79306
2024-01-31 09:21 asshank Note Added: 79363
2024-01-31 14:32 tibor.pacalat Note Added: 79364
2024-01-31 14:32 tibor.pacalat Bug heat 6 => 8
2024-01-31 14:32 tibor.pacalat Assigned To gabrieljenik => tibor.pacalat
2024-01-31 14:32 tibor.pacalat Status assigned => in testing
2024-01-31 14:55 asshank Note Added: 79366
2024-01-31 17:59 Changeset attached => LimeSurvey master a908e85d
2024-01-31 17:59 guest Note Added: 79381
2024-01-31 17:59 guest Bug heat 8 => 10
2024-01-31 18:03 tibor.pacalat Status in testing => resolved
2024-01-31 18:03 tibor.pacalat Resolution open => fixed
2024-01-31 19:05 asshank Note Added: 79382
2024-02-01 10:05 tibor.pacalat Note Added: 79383
2024-02-01 12:45 asshank Note Added: 79389
2024-02-02 12:24 tibor.pacalat Note Added: 79393
2024-02-15 21:23 gabrieljenik Assigned To tibor.pacalat => DenisChenu
2024-02-15 21:23 gabrieljenik Status resolved => ready for code review
2024-02-15 21:23 gabrieljenik Note Added: 79532
2024-02-16 10:43 DenisChenu Assigned To DenisChenu => gabrieljenik
2024-02-16 10:43 DenisChenu Status ready for code review => in code review
2024-02-26 13:55 Changeset attached => LimeSurvey 5.x c22d893c
2024-02-26 13:55 guest Note Added: 79641
2024-03-07 14:50 tibor.pacalat Status in code review => resolved
2024-06-25 17:23 c_schmitz Status resolved => closed