[wp-hackers] Have I gone mad?

Peter van der Does peter at avirtualhome.com
Mon Apr 29 11:40:24 UTC 2013


On Mon, 29 Apr 2013 08:46:20 +0100
David Anderson <david at wordshell.net> wrote:

> 
> >   if (!isset($_POST['updraft_**restore']) ||
> > !is_array(maybe_unserialize($_POST['updraft_**restore']))) {
> 
> I've obviously created something of a red herring by serialising the
> error output and unserialising it together with a typo. Let me
> explain the problem a different way:
> 
> Here is the code:
> 
>          if (!isset($_POST['updraft_restore'])
> || !is_array($_POST['updraft_restore'])) { echo '<p>'.__('ABORT:
> Could not find the information on which entities to restore.',
> 'updraftplus').'</p>'; return false; }
> 
> I have a user who (every time) hits this error condition. When I get
> him to print_r his $_POST array (in the same code, so there's no
> other code editing the $_POST array), he gets this:
> 
> Array (
>      [action] => updraft_restore
>      [backup_timestamp] => 1366984477
>      [updraft_restore] => Array
>          (
>              [0] => plugins
>              [1] => themes
>              [2] => uploads
>              [3] => others
>              [4] => db
>          )
> )
> 
> How can that happen??
> 
> David
> 

These are one of these thing where I go crazy on parenthesis. If have
struggled with the NOT's and AND/OR in other programming languages. Sometimes 
the first NOT would negate the ||, making it &&. So your first condition would 
be not isset (= FALSE), 2nd not is_array ( = FALSE), but not instead of || it's &&
and so FALSE && FALSE, yup that is true, error hits.

So i just wrap each condition in parenthesis.

if ( ( !isset($_POST['updraft_restore']) ) || ( !is_array($_POST['updraft_restore'] ) ))

I know it's not an explanation, but a solution. Maybe it has to do with 
the PHP version, I don't know.

-- 
Peter van der Does

GPG key: CB317D6E

Site: http://avirtualhome.com
GitHub: https://github.com/petervanderdoes
Twitter: @petervanderdoes



More information about the wp-hackers mailing list