Bug #19938

warning: in_array wrong datatype

Added by Franz Holzinger over 12 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
felogin
Target version:
-
Start date:
2009-01-30
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
4.5
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

I get a warning message:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/jambage.com/public_html/typo3_src-4.2.5/typo3/sysext/felogin/pi1/class.tx_felogin_pi1.php on line 569
on the page
http://www.jambage.com/index.php?id=213&tx_ttboard_pi_list[uid]=2186&cHash=d5fd8d83c1
after login.

(issue imported from #M10303)


Related issues

Related to TYPO3 Core - Bug #23324: getPreserveGetVars does not work as expectedClosed2010-07-31

Actions
Related to TYPO3 Core - Bug #36894: [felogin] Wrong action url when nested array is passedClosed2012-05-06

Actions
Related to TYPO3 Core - Bug #38589: Error in tx_felogin_pi1->getPreserveGetVarsClosed2012-07-03

Actions
Related to TYPO3 Core - Bug #23649: felogin::getPreserveGetVars() decode encoded valuesClosed2010-09-29

Actions
Related to TYPO3 Core - Bug #42705: PHP Warning: in_array() is boolean in feloginClosed2012-11-05

Actions
#1

Updated by Steffen Kamper over 12 years ago

Which Version?
Do you have preserveGETvars defined?

#2

Updated by Franz Holzinger over 12 years ago

This has been shipped with TYPO3 4.2.5.

My Setup is:

plugin.tx_felogin_pi1 {
templateFile = fileadmin/templates/template.html
showPermaLogin = 1
showForgotPasswordLink = 1
preserveGETvars = tx_ttboard_pi_tree[uid],tx_ttboard_pi_list[uid]=2168,cHash
}

I have seen that sometimes I get logged out immediately.

#3

Updated by Steffen Kamper over 12 years ago

you have an error in definition:

preserveGETvars = tx_ttboard_pi_tree[uid],tx_ttboard_pi_list[uid]=2168,cHash

remove =2168 and try again

#4

Updated by Franz Holzinger over 12 years ago

I have made this change now.
But still the same PHP warning:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/mysite.com/public_html/typo3_src-4.2.5/typo3/sysext/felogin/pi1/class.tx_felogin_pi1.php on line 569

#5

Updated by Markus Kappe almost 12 years ago

Tracked the problem (TYPO3 4.2.8, felogin 1.0.0)
class.tx_felogin_pi1.php line 562
$preserveVars =! ($this->conf['preserveGETvars'] || $this->conf['preserveGETvars']=='all' ? array() : implode(',', (array)$this->conf['preserveGETvars']));

While $this->conf['preserveGETvars'] holds comma separated values, it is clear that this cannot work.

Another related bug is that preserveGETvars does only work for one-dimensional arrays. If you have parameters like &myext[param][0]=somevalue it will resolve as &myext[param]=Array

I have just re-written the function, now it works with multidimensional arrays (needs at least php 5.1)

/** * Is used by TS-setting preserveGETvars * possible values are "all" or a commaseperated list of GET-vars * they are used as additionalParams for link generation * REWRITTEN BY @29.09.2009 * * @return string additionalParams-string
*/
protected function getPreserveGetVars() {
static $params = null;
if (!is_null($params)) { return $params; } // caching
$getVars = t3lib_div::_GET();
unset($getVars['id'], $getVars['no_cache'], $getVars['logintype'], $getVars['redirect_url'], $getVars['cHash']); // never preserve this vars
if ($this->conf['preserveGETvars'] == 'all') {
return $params = http_build_query($getVars);
}
$preserveVars = t3lib_div::trimExplode(',', $this->conf['preserveGETvars']); // 'all' and [empty] dont come to here
parse_str(join('=1&', $preserveVars).'=1', $preserveArray); // convert preserveVars to array structure

$intersect = $this->myIntersect($getVars, $preserveArray);
return $params = '&'.http_build_query($intersect);
}
/**
 * calculates intersection of two arrays like array_intersect_key but recursive
 * INTRODUCED BY  @29.09.2009     
 *
 * @param  array/mixed  master array
 * @param  array        array that has the keys which should be kept in the master array
 * @return array/mixed  cleand master array
*/
function myIntersect($master, $mask) {
if (!is_array($master)) { return $master; }
foreach ($master as $k=>$v) {
if (!isset($mask[$k])) { unset ($master[$k]); continue; } // remove value from $master if the key is not present in $mask
if (is_array($mask[$k])) { $master[$k] = $this->myIntersect($master[$k], $mask[$k]); } // recurse when mask is an array
// else simply keep value
}
return $master;
}
?>
#6

Updated by Markus Klein almost 12 years ago

Line 562 has two other issues.

Take a look at this operator

$preserveVars = ! ( $this->conf['preserveGETvars'] || $this->conf['preserveGETvars']=='all' ? array() : implode(',', (array)$this->conf['preserveGETvars']) ) ;

1.)

which is interpreted as: variable = ! (something)

finally $preserveVars is a boolean value!
Thats the reason for Franz's warning.

I guess it should be: = ( ! $this->conf['preserveGETvars'] || ...

Line 562 will not throw a warning as (array)$this->conf['preserveGETvars'] will result in an array with only one string as item 0. Imploding it converts it back to a string.

2.)
The inline if returns two different datatypes in either case. array (array()) and string (implode())

Nonetheless it's a good idea to implement Markus Kappe's solution!

By the way: nice greetings to Markus Kappe. As you've done our Vienna Dance website ;-)

#7

Updated by Jigal van Hemert over 9 years ago

  • Status changed from New to Under Review
  • Target version changed from 0 to 1525
  • TYPO3 Version set to 4.5
#8

Updated by Steffen Ritter over 9 years ago

  • Target version changed from 1525 to 4.7.0-beta1
#9

Updated by Steffen Ritter over 9 years ago

  • Target version changed from 4.7.0-beta1 to 4.7.0-beta2
#10

Updated by Steffen Ritter over 9 years ago

  • Target version deleted (4.7.0-beta2)
#11

Updated by Jo Hasenau over 9 years ago

Acutally this can be fixed easily, since $preserveVars is expected to return an array, which is empty in case preserveGETvars is NOT set or set to "all". Otherwise it will contain the exploded values of a former comma separated list.

We have fixed it for our project by changing the line like this:

$preserveVars = (
    !$this->conf['preserveGETvars'] || 
    $this->conf['preserveGETvars']=='all' ? 
        array() : 
        t3lib_div::trimExplode(',', $this->conf['preserveGETvars'])
);

And it works flawlessly.

#12

Updated by Gerrit Code Review almost 9 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#13

Updated by Gerrit Code Review almost 9 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#14

Updated by Gerrit Code Review almost 9 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#15

Updated by Gerrit Code Review almost 9 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#16

Updated by Gerrit Code Review almost 9 years ago

Patch set 7 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#17

Updated by Gerrit Code Review almost 9 years ago

Patch set 8 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#18

Updated by Gerrit Code Review almost 9 years ago

Patch set 9 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#19

Updated by Gerrit Code Review almost 9 years ago

Patch set 10 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#20

Updated by Gerrit Code Review over 8 years ago

Patch set 11 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#21

Updated by Gerrit Code Review over 8 years ago

Patch set 12 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#22

Updated by Gerrit Code Review over 8 years ago

Patch set 13 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#23

Updated by Gerrit Code Review over 8 years ago

Patch set 14 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#24

Updated by Gerrit Code Review over 8 years ago

Patch set 15 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#25

Updated by Gerrit Code Review over 8 years ago

Patch set 16 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#26

Updated by Gerrit Code Review over 8 years ago

Patch set 17 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638

#27

Updated by Jigal van Hemert over 8 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#28

Updated by Gerrit Code Review over 8 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch TYPO3_4-7 has been pushed to the review server.
It is available at http://review.typo3.org/16452

#29

Updated by Gerrit Code Review over 8 years ago

Patch set 2 for branch TYPO3_4-7 has been pushed to the review server.
It is available at https://review.typo3.org/16452

#30

Updated by Jigal van Hemert over 8 years ago

  • Status changed from Under Review to Resolved
#31

Updated by Benni Mack almost 3 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF