Page MenuHomePhabricator

PHP "Only variables should be passed by reference" error when running maintenance script SMW_refreshdata.php
Closed, ResolvedPublic

Description

Author: subs.gvh

Description:
When installing and executing the PHP script "SMW_refreshdata.php" in extensions/SemanticMediaWiki/maintenance, I get the following error:

"PHP Strict Standards: Only variables should be passed by reference in C:\xampp\
htdocs\mediawiki\extensions\SemanticMediaWiki\includes\storage\SMW_SQLStore2.php
on line 839"

a number of times. Not sure what the impact is.

Further details: I am installing SMW+ extensions, after which I run the "SMW_refreshdata.php" script.


Version: unspecified
Severity: minor

Details

Reference
bz27360

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:14 PM
bzimport set Reference to bz27360.

subs.gvh wrote:

It happened after installing the automaticsemanticforms of SMW+.

This is not an error but merely a notice that points to a use of PHP functions that is not completely conforming to the specification. Production sites should be configured to not show these messages at all (php.ini defines what is shown, do not enable STRICT and NOTICE unless you are a developer).

In your case, the reason for the message might be a number of uses of reset() on return values of functions. We will be eliminating these at some point. A number of calls to the function end() have recently been eliminated in SVN. Neither cause problems in practice.

This looks like an SMW+ issue really. The warning is probably coming from automaticsemanticforms making an incorrect call to the SMW SQL store.

In any case, whet version of SMW are you using? Did it came bundled with SMW+ (and have a bunch of patches with it)? If so, you should report this to Ontoprise.

subs.gvh wrote:

Thanks for answering.
I got the latest version of both SMW (1.5.5)and SMW+ (1.5.2).
I thought it might be SMW+ wrongly calling SMW methods as well.
Will report it to them.

Markus: Unless you disagree with this being SMW+s doing it wrong, this can be marked as invalid.

Our code still has things like

$dv = reset( $data->getPropertyValues( $property ) );

which should cause this message to appear as well (or does it not?). If this is the case, the bug should remain open until we rewrote all such uses to something like

$values = $data->getPropertyValues( $property );
$dv = reset( $values );

I wonder if there isn't a more direct way of getting the first/last element of a PHP array without assigning it to a variable first.

Indeed there is:

$dv = array_shift( $data->getPropertyValues( $property ) );

For the last element you can use array_pop()

As I read the documentation [1], array_shift also assumes a call-by-ref parameter, so should yield the same message.

[1] http://php.net/manual/en/function.array-shift.php

I have just checked our code for all uses of reset(), array_shift() and array_pop(). I think it is safe to close this bug now.