Re: newbie: help with array
| From: | Ernest E Vogelsinger | Date: | Mon, 28 Apr 2003 13:32:25 +0000 |
| Subject: | Re: newbie: help with array | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145523@lists.php.net to get a copy of this message | ||
At 15:14 28.04.2003, patlebon spoke out and said:
--------------------[snip]--------------------
>The check permission only works when the permission is in the array. When
>the array does not contain the required permission the following error is
>thrown:
>
>Notice: Undefined offset: 3 in C:\Inetpub\...\menu.php on line 29
>
>Any ideas what may be casuing this? Thanks for your help so far.
>
>
>
>"Marek Kilimajer" <kilimajer@webglobe.sk> wrote in message
>news:3EAD0B3E.9050901@webglobe.sk...
>> Something like:
>> // set permissions
>> while($perm = mysql_fetch_assoc($res)){
>> $_SESSION['userPermissions'][$perm['userPermission']]=1;
>> }
>>
>> //check permission
>> if($_SESSION['userPermissions']['read']) {
>> //is allowed to read
>> }
--------------------[snip]--------------------
This is a notification only. PHP tells you that you're accessing an index
of an array that is not defined ($perm['userPermission']). PHP tells you
this because it may be a logical error within your application - but here
it isn't.
You may safely (here ;->) turn notifications off either by editing php.ini,
or by adding the line
error_reporting(E_ALL & ^E_NOTICE);
to your script to remove such notifications.
From PHP.INI:
; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
; E_ALL - All errors and warnings
; E_ERROR - fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
A valid configuration where only runtime fatal errors are reported would be
error_reporting(E_ERROR);
Better use
error_reporting(E_ALL & ^(E_NOTICE | E_WARNING));
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/