Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8 null arrays issue #14

Closed
jangari opened this issue Jul 26, 2023 · 2 comments
Closed

PHP8 null arrays issue #14

jangari opened this issue Jul 26, 2023 · 2 comments

Comments

@jangari
Copy link

jangari commented Jul 26, 2023

We are getting the following error from the CSS injector:

The 'redcap_css_injector' module threw the following exception when calling the hook method 'redcap_survey_page_top':

TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in /var/www/html/modules/redcap_css_injector_v1.1.1/ExternalModule.php:93
Stack trace:
#0 /var/www/html/modules/redcap_css_injector_v1.1.1/ExternalModule.php(93): array_keys()
#1 /var/www/html/modules/redcap_css_injector_v1.1.1/ExternalModule.php(75): CSSInjector\ExternalModule\ExternalModule->_getFormattedSettings()
#2 /var/www/html/modules/redcap_css_injector_v1.1.1/ExternalModule.php(40): CSSInjector\ExternalModule\ExternalModule->getFormattedSettings()
#3 /var/www/html/modules/redcap_css_injector_v1.1.1/ExternalModule.php(28): CSSInjector\ExternalModule\ExternalModule->applyStyles()
#4 /var/www/html/redcap_v13.8.2/ExternalModules/classes/ExternalModules.php(3162): CSSInjector\ExternalModule\ExternalModule->redcap_survey_page_top()
#5 /var/www/html/redcap_v13.8.2/ExternalModules/classes/ExternalModules.php(3327): ExternalModules\ExternalModules::startHook()
#6 /var/www/html/redcap_v13.8.2/ExternalModules/classes/ExternalModules.php(3360): ExternalModules\ExternalModules::ExternalModules\{closure}()
#7 /var/www/html/redcap_v13.8.2/Classes/Hooks.php(42): ExternalModules\ExternalModules::callHook()
#8 /var/www/html/redcap_v13.8.2/Surveys/index.php(3051): Hooks::call()
#9 /var/www/html/surveys/index.php(9): include('...')
#10 {main}

URL: <redacted>
Server: r<redacted>
User: [survey respondent]
Project ID: <redacted>
Module Name: REDCap CSS Injector (redcap_css_injector)
Module Author(s): [email protected], [email protected], [email protected]
Run Time: 0 seconds

Looks like initialising $value = $value ?? [] before line 93 in this block will fix it. I will test this and submit a PR if successful.

@pbchase
Copy link
Contributor

pbchase commented Aug 21, 2023

This issue sounds like this comment in the REDCap community:

pierre.hebel asked • 3 days, 24 minutes ago (2023-08-18 09:56)
Redcap CSS Injector EM not compatible with PHP 8
REDCap 13.8.1 · PHP 8.0.27 (Linux/Unix OS) · MariaDB 10.5.18

Hi,

@philip.chase

i wanted to play with Redcap CSS injector but the EM on Repo is not compatible with PHP 8 .

The problem seems to come from the order of definition of variables in function calls. The required variables must be positioned before the optional ones.

Optional parameters specified before required parameters
An optional parameter specified before required parameters is now always treated as required, even when called using named arguments. As of PHP 8.0.0, but prior to PHP 8.1.0, the below emits a deprecation notice on the definition, but runs successfully when called. As of PHP 8.1.0, an error of class ArgumentCountError is thrown, as it would be when called with positional arguments.

Unless I am mistaken, this should be corrected by intervening on lines 17 and 24 by reordering the variables as follows:

function redcap_data_entry_form_top($project_id, $instrument, $event_id, $record = null, $group_id = null, $repeat_instance = 1) {

function redcap_survey_page_top($project_id, $instrument, $event_id, $survey_hash, $record = null, $group_id = null, $response_id = null, $repeat_instance = 1) {

Update : after modifying these lines, the EM works partially : works only if no form selected (leave parameter blank)

@pbchase
Copy link
Contributor

pbchase commented Dec 11, 2023

We couldn't reproduce this bug, but we made the change requested in the initial submission and it appears to be benign. The change is included in release 1.1.2. That release has been submitted to the REDCap Repo just now.

If 1.1.2 doesn't fix this issue, we'll need a more detailed bug report that allows us to reproduce the error.

@pbchase pbchase closed this as completed Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants