Connections-Business-Directory / Connections

Directory Plugin for WordPress
https://connections-pro.com
GNU General Public License v2.0
26 stars 18 forks source link

Warning: in_array() expects parameter 2 to be array, null given from class.settings-api.php #315

Closed quantumJLBass closed 10 years ago

quantumJLBass commented 10 years ago

Hello, I needed to change https://github.com/shazahm1/Connections/blob/develop/includes/settings/class.settings-api.php#L663

to

$checked = checked( TRUE , (is_array($value))? (in_array($key, $value)) : ($key==$value) , FALSE );

l see the same thing on https://github.com/shazahm1/Connections/blob/develop/includes/settings/class.settings-api.php#L623 . It just seems that I was able to get the value as a string, and althou I corrected it soon in the chain that lead here (registering the setting fields) I think it may be wise to just ensure that the values are accounted for?

shazahm1 commented 10 years ago

I do know a string is possible, which is why I cast as an (array). Guess I missed one. Id opted for that method because it seemed to be a simple solution. Is what I did considered poor practice?

quantumJLBass commented 10 years ago

poor practice is relevant imho. I try to insure that, although I can't strong type a var, that I at the least account for possible type collisions even if they are able to be set correct above. I do this any time I have a var or property that can be used in a way that leads to that var being casted as different types. In this case, I switch a select field to a muiltselect. The default value would have still been one value, so I spaced that the there would be a default switch. For example of my mistake,

'default' => 'keyword'

needed to change to

'default' => array('keyword')

I tend to be a little more of a measure thrice cut once type of programmer. Comes from strong type'd languages I use like C# and what not. My report was more an alert that it was possible to get from a config type area to the functional to produce the warning