#118 Notice: Undefined variable: permissions in functions.php

open
nobody
None
1
2012-02-18
2012-02-05
John Guy
No

Hi

I was making some changes to my local copy of your site (version 3.1.0) and I turned on error reporting, I got an unexpected messages from the functions.php file...

Notice: Undefined variable: permissions in C:\xampp\htdocs\froggit.local\core\functions.php on line 737

I have checked the code and it appears to be the line...

$permissions |= $_SESSION['vdb']['permissions']['all'];

I understand that this line is checking that the permissions are either correct for the user or set as 'all'. however I can not find any other reference in the sites code to a variable called $permissions so how is this variable being populated? Is it safe to comment out the references to $permissions in the functions.php file to stop the warnings or am I missing something?

Thanks for your help I am new to php coding and want to understand how this works,

:0)

Discussion

  • Well, it's just a notice. And I really wonder that this is the only one.

    The usal setting for error_reporting is: E_ALL & ~E_NOTICE or you will often get flooded with notices.
    Or turn off display_errors an turn on log_errors - then only the log gets flooded.

     
    • priority: 5 --> 1
     
  • Justin Pasher
    Justin Pasher
    2012-02-20

    Just to offer up my two cents (it's been quite a few years since I last messed around with the VideoDB code).

    If you look at the surrounding code, the line in question doesn't even make sense. It's the first assignment of $permissions within the function, and it's trying to OR it with itself (meaning it will always be 0 || $_SESSION['vdb']['permissions']['all']. Changing it to a straight assignment corrects the notice and keep the same functionality.

    My personal opinion on PHP notices is that code should NEVER spit out any PHP notices. If it does, it's a sign of improper error checking and/or variable initialization, which is a bad programming habit to get into. It can also lead to unexpected results in some situations (for example, a misspelled variable name).

    Turning off PHP error reporting in a production environment is another story, but this situation is different.