Bug #19938
closedwarning: in_array wrong datatype
Added by Franz Holzinger almost 16 years ago. Updated about 6 years ago.
100%
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)
Updated by Steffen Kamper almost 16 years ago
Which Version?
Do you have preserveGETvars defined?
Updated by Franz Holzinger almost 16 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.
Updated by Steffen Kamper almost 16 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
Updated by Franz Holzinger almost 16 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
Updated by Markus Kappe about 15 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 MARKUS.KAPPE@DIX.AT @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 MARKUS.KAPPE@DIX.AT @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;
}
?>
Updated by Markus Klein about 15 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 ;-)
Updated by Jigal van Hemert almost 13 years ago
- Status changed from New to Under Review
- Target version changed from 0 to 1525
- TYPO3 Version set to 4.5
Updated by Steffen Ritter almost 13 years ago
- Target version changed from 1525 to 4.7.0-beta1
Updated by Steffen Ritter over 12 years ago
- Target version changed from 4.7.0-beta1 to 4.7.0-beta2
Updated by Steffen Ritter over 12 years ago
- Target version deleted (
4.7.0-beta2)
Updated by Jo Hasenau over 12 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.
Updated by Gerrit Code Review over 12 years ago
Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review over 12 years ago
Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review over 12 years ago
Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review over 12 years ago
Patch set 6 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review over 12 years ago
Patch set 7 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 8 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 9 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 10 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 11 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 12 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 13 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 14 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 15 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 16 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Gerrit Code Review about 12 years ago
Patch set 17 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/7638
Updated by Jigal van Hemert about 12 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset a0f4d13c9f53431a62845bbad31ff11bc5d5c2ef.
Updated by Gerrit Code Review about 12 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
Updated by Gerrit Code Review almost 12 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
Updated by Jigal van Hemert almost 12 years ago
- Status changed from Under Review to Resolved
Applied in changeset 9eca09b08b257fbdcc4053d88d1df3feeb9afd66.