Bug #19938

warning: in_array wrong datatype

Added by Franz Holzinger almost 11 years ago. Updated about 1 year ago.

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

100%

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 expected Closed 2010-07-31
Related to TYPO3 Core - Bug #36894: [felogin] Wrong action url when nested array is passed Closed 2012-05-06
Related to TYPO3 Core - Bug #38589: Error in tx_felogin_pi1->getPreserveGetVars Closed 2012-07-03
Related to TYPO3 Core - Bug #23649: felogin::getPreserveGetVars() decode encoded values Closed 2010-09-29
Related to TYPO3 Core - Bug #42705: PHP Warning: in_array() is boolean in felogin Closed 2012-11-05

Associated revisions

Revision a0f4d13c (diff)
Added by Jigal van Hemert about 7 years ago

[BUGFIX] EXT:felogin: Multiple bugs with preserveGETvars

Refactor and fix handling of preserveGETvars in felogin. * Add support for multi dimensional arrays * urlencode() values * Preserve only parameters defined in 'preserveGETvars'

The patch adds a new ArrayUtility method to handle
recursive array intersections. See the unit tests for details.

Change-Id: I90e2f8eb79586369a9c15c7ef19f7658b1d65ed3
Fixes: #19938
Fixes: #23324
Fixes: #23649
Fixes: #36894
Fixes: #38589
Releases: 6.0, 4.7
Reviewed-on: http://review.typo3.org/7638
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn

Revision 6716a6fa (diff)
Added by Christian Kuhn about 7 years ago

[BUGFIX] Follow-up clean-up to #19938

Refactoring #19938 a loose end was forgotten to be removed in one test.

Change-Id: I36d1f9368eb829afebd5c3be2282811b010ed5ff
Related: #19938
Releases: 6.0
Reviewed-on: http://review.typo3.org/16453
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn

Revision 9eca09b0 (diff)
Added by Jigal van Hemert almost 7 years ago

[BUGFIX] EXT:felogin: Multiple bugs with preserveGETvars

Refactor and fix handling of preserveGETvars in felogin. * Add support for multi dimensional arrays * urlencode() values * Preserve only parameters defined in 'preserveGETvars'

The patch adds a new ArrayUtility method to handle
recursive array intersections. See the unit tests for details.

Change-Id: I90e2f8eb79586369a9c15c7ef19f7658b1d65ed3
Fixes: #19938
Fixes: #23324
Fixes: #23649
Fixes: #36894
Fixes: #38589
Releases: 6.0, 4.7
Reviewed-on: https://review.typo3.org/16452
Reviewed-by: Markus Klein
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn

History

#1 Updated by Steffen Kamper almost 11 years ago

Which Version?
Do you have preserveGETvars defined?

#2 Updated by Franz Holzinger almost 11 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 almost 11 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 almost 11 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 over 10 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 about 10 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 almost 8 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 almost 8 years ago

  • Target version changed from 1525 to 4.7.0-beta1

#9 Updated by Steffen Ritter almost 8 years ago

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

#10 Updated by Steffen Ritter almost 8 years ago

  • Target version deleted (4.7.0-beta2)

#11 Updated by Jo Hasenau almost 8 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 over 7 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 over 7 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 over 7 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 over 7 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 over 7 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 over 7 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 over 7 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 over 7 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 about 7 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 about 7 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 about 7 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 about 7 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 about 7 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 about 7 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 about 7 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 about 7 years ago

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

#28 Updated by Gerrit Code Review about 7 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 almost 7 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 almost 7 years ago

  • Status changed from Under Review to Resolved

#31 Updated by Benni Mack about 1 year ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF