2

I have a snippet of code that looks like so:

if(array_key_exists('uid',$_SESSION)){
     $userdata->readUser($_SESSION['uid']); 
     $ACL = new ACL($_SESSION['uid']);
     $userPerms = $ACL->setACL();
     if(!in_array_r("adminUI",$userPerms['perms'],true)){
        echo "Couldnt fine adminUI in:";
         var_dump($userPerms['perms']); 
     }
}

And the in_array_r function is:

function in_array_r($needle, $haystack, $strict = false) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }

    return false;
}

Which I got from: in_array() and multidimensional array

However the output of this shows:

Couldnt fine adminUI in:
array(2) {
  [0]=>
  array(1) {
    ["perm_desc"]=>
    string(7) "adminUI"
  }
  [1]=>
  array(1) {
    ["perm_desc"]=>
    string(9) "apiAccess"
  }
}

If i change the function to check the array without STRICT it will find the needle, but FAILS on strict check...

I'm beating my head into the desk trying to figure this one out.

EDIT

Jan Schejbal was awesome enough to point out that this code works perfectly fine. I was not coherent enough to realize my working directory. Thank you again Jan Schejbal.

Community
  • 1
  • 1
Hydra IO
  • 1,429
  • 1
  • 13
  • 27
  • 1
    I was unable to reproduce the issue. Check your files for unprintable characters using an editor that shows them, and fix the typos in the error message and run the program again. If it shows the error message with typos, you are running an old version or have another copy of the error-message generating code. – Jan Schejbal Jan 28 '13 at 03:39
  • Wow........I'm almost embarrassed to admit my mistake. I was editing the github version, and not the test environment. I could thank you a million times over. I'm going to blame it on sleep deprivation and Aptana not reminding me I had 1 local file and 1 server version open. – Hydra IO Jan 28 '13 at 03:49
  • Added it as an answer. This is a mistake everyone makes at some point (guess how it came to my mind...). – Jan Schejbal Jan 28 '13 at 03:54

1 Answers1

1

I originally posted this as a comment, but since it indeed was the answer to the question...

If you have a totally WTF error:

  1. Change the error message and run the program again. If it shows the original error message, you are running a different file than you are editing (e.g. not uploading, wrong directory) or have another copy of the error-message generating code somewhere.

  2. Check your files for unprintable characters using an editor that shows them

No. 1 is one of the most common reasons for unexplainable errors.

Jan Schejbal
  • 3,820
  • 16
  • 38