Cannot use a scalar as an array

Before I file a bug report, I have a sense I asked about this before, but I can’t find it in GitHub or on this forum, so I apologize for any redundancy.

I’m running OJS 3 beta, pulled from the HEAD of GitHub. The error log is full of:

PHP Warning:  Cannot use a scalar value as an array in .../lib/pkp/classes/core/DataObject.inc.php on line 133, referer: ...

This seems different from the errors reported against OJS 2.x; I have in my head that it’s related to monolingual affiliation, but I can’t remember why.

Any tips or ideas?

Hi @crism,

Is this a new database installation, or did it already exist? Usually this kind of message arises when the multilingual capabilities of a field have changed but the database doesn’t reflect that.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher, it’s been doing this since it was first installed from scratch.

Hi @crism,

Can you use error_log or similar to dump out $key in lib/pkp/classes/core/DAO.inc.php near line 133 when !is_array($this->_data[$key])?

Regards,
Alec Smecher
Public Knowledge Project Team

Lots of indices seem to cause the problem. I changed line 133 to this:

	if (!is_array($this->_data[$key])) {
		error_log(print_r($key,true));
		error_log(print_r($this->_data[$key],true));
	}
	$this->_data[$key][$locale] = $value;

I got back screensful of trios like this:

[Mon Apr 04 10:06:34.284115 2016] [:error] [pid 11858] [client 130.126.35.82:57322] submissionFeeDescription, referer: ...
[Mon Apr 04 10:06:34.284119 2016] [:error] [pid 11858] [client 130.126.35.82:57322] PHP Notice:  Undefined index: submissionFeeDescription in .../lib/pkp/classes/core/DataObject.inc.php on line 135, referer: ...
[Mon Apr 04 10:06:34.284124 2016] [:error] [pid 11858] [client 130.126.35.82:57322] , referer: ...

… for lots of different indices (not just submissionFeeDescription). So… maybe it is a database problem, except as I said, this started as soon as I installed.

More detailed debugging info shows:

Issue::setData(hideCoverPageArchives, 0, en_US): $this->_data[$key] is not array
PHP Warning:  Cannot use a scalar value as an array in ...

I think this is a bug in DataObject::setData(). Filing it…

Filed as [OJS] issue cover settings save inappropriate null-locale values, causing PHP scalar errors · Issue #1336 · pkp/pkp-lib · GitHub.

Hi,

I still have the same Problem after updating to OJS 3.0.2. Is there any solution to get rid of this warnings in the meanwhile?

Hi @Lydia_Mueller,

There are a couple of issues in this thread. Can you describe in detail?

Regards,
Alec Smecher
Public Knowledge Project Team

I mean the original issue. In the error log of my webserver running the OJS (3.0.2), I still have a lot warnings saying

PHP Warning: Cannot use a scalar value as an array in /var/www/html/ojs/lib/pkp/classes/core/DataObject.inc.php on line 133, referer:

Is there anything I can do to get rid of the warning?

Hi @Lydia_Mueller,

If you’re handy with PHP, try walking through the debugging steps earlier in this thread to identify which settings are causing the problems. If not, I’d suggest just ignoring the warnings for now.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,
I upgrade without problems from version 2.4.8.1 to 3.0.2. After the upgrade version check the Usage stats, but it doesn’t work. it did the files and the ran the process but when I check the table metrics never update the stats. After that I need to check why is not upload. so, I set the php.ini with the error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED and the config.inc.php with [debug] show_stacktrace = On , display_errors = On, deprecation_warnings = On and log_web_service_info = On. after moved the file in the stage folder and I ran the next line php for OJS 3.0.2 /var/www/html/ojs/tools/runScheduledTasks.php /var/www/html/ojs/lib/pkp/plugins/generic/usageStats/scheduledTasks.xml
but the error show me

Can you help me how can solve this problem?, or how can check what is the real problem?.

Thanks in advance !!!

Hi @JCar,

The cause of this message is a mix of localized (locale column is set) and non-localized (locale column is empty or null) for a single setting_name, which is a data error. Follow some of the debugging suggestions here to find out what the setting_name in question is, then review the data in your database to see what it looks like.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,
I checked all about your sugesstions in the special about the locale in the table issue_settings where I found some null value in the field locale, after fix it I check again the table issue_settings (select locale, Count(locale) from issue_settings group by locale;) and the result is:
image

I ran again the script /var/www/html/ojs/tools/runScheduledTasks.php /var/www/html/ojs/lib/pkp/plugins/generic/usageStats/scheduledTasks.xml but I have the same problem
image

Do you have idea what tables I need to check about the locale field or other fields?
Really I don’t understand whats is happen, because in the version 2.4.8.2 the statistics was working every day for the information update .

Can you help me?

Thanks in advance.

Hi @JCar,

There should be some entries with locale is null or locale = '' – it’ll depend on what setting_name (it doesn’t make sense to localize ISSNs, for example, but it does make sense to localize titles). The debugging procedures suggested on this issue will help to identify which specific setting_name has entries for both locale is null or locale = '' and locale is not null and locale <> '' for the same setting_name. That’ll be the key to debugging further.

If you’ve forced all rows to have a locale entry, then you’ll likely be causing more problems – I’d strongly suggest reverting this change.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,
I revert the change. because I don’t have data with Null, I preferred reverting the change, Thanks for your suggestion. so, I have the same problem, how can I check what’s is the real mistake?

sorry @asmecher, Really I don’t undertand what is the correct form for check what is the posible problem…would can help me ?

Hi @JCar/all,

You can debug this by editing lib/pkp/classes/core/DataObject.inc.php, and finding line 133 or so, which should look like:

$this->_data[$key][$locale] = $value;

Just before this, add:

if (isset($this->_data[$key]) && !is_array($this->_data[$key])) error_log('Mixed localization for ' . get_class($this) . ', setting "' . $key . '"');

Then trigger the warning again (e.g. by reloading the page you saw it on before), and look in your log for more details.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Hi @asmecher,
Thank you for your suggestions about the code. So now I know what is the problem I have more than one metacitations in one journal.
image

Can you suggest me how rows I need to delete or how can fix the problem. I tried delete the journal_id 13,14,15 than locale=’’, moved one log on folder stage and after ran the script /var/www/html/ojs/tools/runScheduledTasks.php /var/www/html/ojs/lib/pkp/plugins/generic/usageStats/scheduledTasks.xml …the task now not show me error, but the file isn’t upload in the table metrics. when I checked the error in the logs in apache show me

PHP Warning: array_merge(): Argument #2 is not an array in /var/www/html/ojs/lib/pkp/classes/core/PKPApplication.inc.php on line 578

can you help me what more steps I need to check for fix the upload the usages statistics ? the problem only is for upload, because the create of files is fine.