white page adding related record

24 views
Skip to first unread message

Ruben Rouw

unread,
Sep 6, 2024, 2:05:14 PM9/6/24
to Xataface
Hi Steve and everyone,

When using php 8.1.or 8.2 or 8.3 I am getting a fatal php error when trying to add a related record

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given

Using latest xataface 3.0.2 5002.

It seems to be the case for any related table.

Not sure if this is a bug or something on my end - i recently upgraded my ubuntu server from 20 to 22 to 24, then back to 22 as I kept getting php errors. I thought I already had php 8.1 to begin with, but now I am not sure anymore.

I haven't found this particular error in any of the posts here and once i noticed it was not table specific, i gave up on trying to hunt down what in my site config may cause it and went back to php7.4 - problem gone.

Example relationship for table Computers:
[Conditions]
__sql__ = "SELECT * FROM Conditions WHERE ComputerID='$ComputerID'"
section:limit=100
action:label = "condition"

If I add a record directly to the related tables, itself, it works fine.

Any ideas appreciated!
Ruben

Full error:

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /var/www/xataface/Dataface/FormTool/select.php:148\nStack trace:\n#0 /var/www/xataface/Dataface/FormTool.php(405): Dataface_FormTool_select->pushValue()\n#1 /var/www/xataface/Dataface/QuickForm.php(936): Dataface_FormTool->pushValue()\n#2 /var/www/xataface/Dataface/ShortRelatedRecordForm.php(582): Dataface_QuickForm->pushValue()\n#3 /var/www/xataface/lib/HTML/QuickForm.php(1635): Dataface_ShortRelatedRecordForm->save()\n#4 /var/www/xataface/actions/new_related_record.php(93): HTML_QuickForm->process()\n#5 /var/www/xataface/Dataface/Application.php(3715): dataface_actions_new_related_record->handle()\n#6 /var/www/xataface/Dataface/Application.php(3857): Dataface_Application->handleRequest()\n#7 /var/www/xataface/Dataface/Application.php(3743): Dataface_Application->_display()\n#8 /var/www/masterlist/index.php(19): Dataface_Application->display()\n#9 {main}\n  thrown in /var/www/xataface/Dataface/FormTool/select.php on line 148

 select.php:

  137         function pushValue(&$record, &$field, &$form, &$element, &$metaValues){
138                 // quickform stores select fields as arrays, and the table schema will only accept
139                 // array values if the 'repeat' flag is set.
140                 $table =& $record->_table;
141                 $formTool =& Dataface_FormTool::getInstance();
142                 //$formFieldName =& $element->getName();
143
144                 if ( !$field['repeat'] ){
145
146                         $val = $element->getValue();
147
148                         if ( @count($val)>0 ){
149                                 return $val[0];
150
151                         } else {
152                                 return null;
153
154                         }
155                 } else {
156                         return $element->getValue();
157                 }
158
159
160
161         }
162
163
164 }

Mario Jakovina

unread,
Sep 8, 2024, 1:31:17 PM9/8/24
to Xataface
I am not an expert in PHP nor Xataface,  but obviously, the problem is that since PHP 8.0.0, count() function throws TypeError
In select.php in line 148 - error occurs when variable $val is not array. (Before PHP 8.0, PHP would only send a warning).

I would try to change line 148 of select.php from:    if ( @count($val)>0 ){
To: if (isset($val[0]){

I hope, Steve would confirm if I am write, but you can try it yourself.
Mario

Mario Jakovina

unread,
Sep 8, 2024, 1:32:34 PM9/8/24
to Xataface
Here is a link about count() in PHP:

Ruben Rouw

unread,
Sep 9, 2024, 11:52:06 AM9/9/24
to Xataface
That did it, thanks Mario!!

The exact replacement line proved to be:

  if ( isset($val[0])){

Best regards,
Ruben

Mario Jakovina

unread,
Sep 10, 2024, 12:43:14 PM9/10/24
to Xataface
Yes, one closing bracket was missing in my reply
Reply all
Reply to author
Forward
0 new messages