473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Understanding error masking in error handling...

Hey all :)

I was wondering about the $error_types (I particularly notice the 's' suffix
when reading the manual) parameter for 'set_error_handler()':

Can be used to mask the triggering of the error_handler function just like
the error_reporting ini setting controls which errors are shown. Without
this mask set the error_handler will be called for every error regardless
to the setting of the error_reporting setting.

And, in my php.ini I have,
error_reporting = E_ALL & ~E_NOTICE

Which - I think - means something like "E_ALL and less severe AND NOT
E_NOTICE in particular".

This may be read wrong, but in essence, what I assume is possible is to
create a mask that very particularly lets you define which errors to handle
with your custom error handler, and which not to. But I cannot find any
documentation telling me how this works.

I would like, rather than having to do something like -

if (DEVELOPMENT_MODE && in_array($error_level, array(E_WARNING,
E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_RECOVERABLE_ERROR,
E_DEPRECATED, E_USER_DEPRECATED)) log_to_screen($message);

- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.

This may seem superfluous, but what I'm creating right now are core services
that should service upwards of hundreds of frontends simultaneously, so
whatever small performance gain I can achieve here and there may lead to a
tremendous effect overall.

Can anyone help me with understanding this masking business? Or I have I
misunderstood the concept entirely? :)

Thanks in advance,
Daniel :)
Nov 7 '08 #1
9 2242
Daniel Smedegaard Buus schreef:
Hey all :)

I was wondering about the $error_types (I particularly notice the 's' suffix
when reading the manual) parameter for 'set_error_handler()':

Can be used to mask the triggering of the error_handler function just like
the error_reporting ini setting controls which errors are shown. Without
this mask set the error_handler will be called for every error regardless
to the setting of the error_reporting setting.

And, in my php.ini I have,
error_reporting = E_ALL & ~E_NOTICE

Which - I think - means something like "E_ALL and less severe AND NOT
E_NOTICE in particular".

This may be read wrong, but in essence, what I assume is possible is to
create a mask that very particularly lets you define which errors to handle
with your custom error handler, and which not to. But I cannot find any
documentation telling me how this works.

I would like, rather than having to do something like -

if (DEVELOPMENT_MODE && in_array($error_level, array(E_WARNING,
E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_RECOVERABLE_ERROR,
E_DEPRECATED, E_USER_DEPRECATED)) log_to_screen($message);

- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.

This may seem superfluous, but what I'm creating right now are core services
that should service upwards of hundreds of frontends simultaneously, so
whatever small performance gain I can achieve here and there may lead to a
tremendous effect overall.

Can anyone help me with understanding this masking business? Or I have I
misunderstood the concept entirely? :)

Thanks in advance,
Daniel :)
Hi Daniel,

I think you need to reread the manual:
http://nl3.php.net/manual/en/functio...or-handler.php

It is important to remember that the standard PHP error handler is
completely bypassed. error_reporting() settings will have no effect and
your error handler will be called regardless - however you are still
able to read the current value of error_reporting and act appropriately.
Of particular note is that this value will be 0 if the statement that
caused the error was prepended by the @ error-control operator.
So your custom errorhandler is called ALWAYS regardless the settings you
put into error_reporting() (or via php.ini).

Your errorhandler must deal with this error then.
The errorhandler is called with a bunch of parameters, the first being
the errornumber as listed here:
http://nl3.php.net/manual/en/functio...-reporting.php

So I am unsure why you care about the 'masking business', since it is of
no concern to you (unless I completely misinterpret your posting).

The passed errornumber can only be 1 of the errors listed (You cannot
have 2 errors at the same time).

Also, if you write your own handler, be sure you check for errorsupression.

Here is the first peice of code of an errorhandler I use often:

function errorHandler($number, $string, $file, $line, $context) {
// If the user uses errorsurperrsion with @, we need to forgive this error!
if (error_reporting() == 0){
// The error was surpressed, return without futher interference.
return;
}
// rest of the errorhandler

}

Good luck,

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 7 '08 #2
Erwin Moller wrote:
Daniel Smedegaard Buus schreef:
>Hey all :)

I was wondering about the $error_types (I particularly notice the 's'
suffix when reading the manual) parameter for 'set_error_handler()':

Can be used to mask the triggering of the error_handler function just
like the error_reporting ini setting controls which errors are shown.
Without
this mask set the error_handler will be called for every error
regardless to the setting of the error_reporting setting.

And, in my php.ini I have,
error_reporting = E_ALL & ~E_NOTICE

Which - I think - means something like "E_ALL and less severe AND NOT
E_NOTICE in particular".

This may be read wrong, but in essence, what I assume is possible is to
create a mask that very particularly lets you define which errors to
handle with your custom error handler, and which not to. But I cannot
find any documentation telling me how this works.

I would like, rather than having to do something like -

if (DEVELOPMENT_MODE && in_array($error_level, array(E_WARNING,
E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_RECOVERABLE_ERROR,
E_DEPRECATED, E_USER_DEPRECATED)) log_to_screen($message);

- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.

This may seem superfluous, but what I'm creating right now are core
services that should service upwards of hundreds of frontends
simultaneously, so whatever small performance gain I can achieve here and
there may lead to a tremendous effect overall.

Can anyone help me with understanding this masking business? Or I have I
misunderstood the concept entirely? :)

Thanks in advance,
Daniel :)

Hi Daniel,

I think you need to reread the manual:
http://nl3.php.net/manual/en/functio...or-handler.php

It is important to remember that the standard PHP error handler is
completely bypassed. error_reporting() settings will have no effect and
your error handler will be called regardless - however you are still
able to read the current value of error_reporting and act appropriately.
Of particular note is that this value will be 0 if the statement that
caused the error was prepended by the @ error-control operator.
Actually, I did read the manual ;) and this part too, but I'm not using
error_reporting(), I'm referring to the last parameter in
set_error_handler(callback $error_handler [, int $error_types]), which is,
and I quote (http://dk2.php.net/set_error_handler),

error_types

Can be used to mask the triggering of the error_handler function just like
the error_reporting ini setting controls which errors are shown. Without
this mask set the error_handler will be called for every error regardless
to the setting of the error_reporting setting.
Which is, in fact, the same quote as in my previous post ;) So, this has the
same effect as error_reporting() would have on the built-in error handler,
only on the custom one.
So your custom errorhandler is called ALWAYS regardless the settings you
put into error_reporting() (or via php.ini).

Your errorhandler must deal with this error then.
The errorhandler is called with a bunch of parameters, the first being
the errornumber as listed here:
http://nl3.php.net/manual/en/functio...-reporting.php

So I am unsure why you care about the 'masking business', since it is of
no concern to you (unless I completely misinterpret your posting).

The passed errornumber can only be 1 of the errors listed (You cannot
have 2 errors at the same time).

Also, if you write your own handler, be sure you check for
errorsupression.

Here is the first peice of code of an errorhandler I use often:

function errorHandler($number, $string, $file, $line, $context) {
// If the user uses errorsurperrsion with @, we need to forgive this
error!
if (error_reporting() == 0){
// The error was surpressed, return without futher interference.
return;
}
// rest of the errorhandler
I did not know of this. Very useful tip! I have previously turned
error_reporting on and off on-the-fly to achieve the same! Thank you very
much :)

Daniel
}

Good luck,

Regards,
Erwin Moller
Nov 7 '08 #3
Daniel Smedegaard Buus schreef:
Erwin Moller wrote:
>Daniel Smedegaard Buus schreef:
>>Hey all :)

I was wondering about the $error_types (I particularly notice the 's'
suffix when reading the manual) parameter for 'set_error_handler()':

Can be used to mask the triggering of the error_handler function just
like the error_reporting ini setting controls which errors are shown.
Without
this mask set the error_handler will be called for every error
regardless to the setting of the error_reporting setting.

And, in my php.ini I have,
error_reporting = E_ALL & ~E_NOTICE

Which - I think - means something like "E_ALL and less severe AND NOT
E_NOTICE in particular".

This may be read wrong, but in essence, what I assume is possible is to
create a mask that very particularly lets you define which errors to
handle with your custom error handler, and which not to. But I cannot
find any documentation telling me how this works.

I would like, rather than having to do something like -

if (DEVELOPMENT_MODE && in_array($error_level, array(E_WARNING,
E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_RECOVERABLE_ERROR,
E_DEPRECATED, E_USER_DEPRECATED)) log_to_screen($message);

- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.

This may seem superfluous, but what I'm creating right now are core
services that should service upwards of hundreds of frontends
simultaneously, so whatever small performance gain I can achieve here and
there may lead to a tremendous effect overall.

Can anyone help me with understanding this masking business? Or I have I
misunderstood the concept entirely? :)

Thanks in advance,
Daniel :)
Hi Daniel,

I think you need to reread the manual:
http://nl3.php.net/manual/en/functio...or-handler.php

>It is important to remember that the standard PHP error handler is
completely bypassed. error_reporting() settings will have no effect and
your error handler will be called regardless - however you are still
able to read the current value of error_reporting and act appropriately.
Of particular note is that this value will be 0 if the statement that
caused the error was prepended by the @ error-control operator.

Actually, I did read the manual ;) and this part too, but I'm not using
error_reporting(), I'm referring to the last parameter in
set_error_handler(callback $error_handler [, int $error_types]), which is,
and I quote (http://dk2.php.net/set_error_handler),

error_types

Can be used to mask the triggering of the error_handler function just like
the error_reporting ini setting controls which errors are shown. Without
this mask set the error_handler will be called for every error regardless
to the setting of the error_reporting setting.

Which is, in fact, the same quote as in my previous post ;) So, this has the
same effect as error_reporting() would have on the built-in error handler,
only on the custom one.
Hi,

Sorry to be so thick, but I do not understand what your problem is then.
You can overrule the default errorhandler (with its associated default
error_reporting levels) with you own customn errorhandler (with it
associated error_reporting levels passed to the function.).

This is your core 'problem', right?:
[quote]
- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.
[/qoute]

So you pass a value to it for the mask:
(as defined here: http://nl3.php.net/manual/en/functio...-reporting.php)
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
8192 E_DEPRECATED
16384 E_USER_DEPRECATED

So, for example, if you want to catch E_WARNING and E_NOTICE: you look
up their values, add them, and pass that value. In this case 2+8=12.

But I have this feeling that I still don't understand what your problem
is. ;-)

<snip>
>Also, if you write your own handler, be sure you check for
errorsupression.

Here is the first peice of code of an errorhandler I use often:

function errorHandler($number, $string, $file, $line, $context) {
// If the user uses errorsurperrsion with @, we need to forgive this
error!
if (error_reporting() == 0){
// The error was surpressed, return without futher interference.
return;
}
// rest of the errorhandler

I did not know of this. Very useful tip! I have previously turned
error_reporting on and off on-the-fly to achieve the same! Thank you very
much :)
Glad to hear that.
I found the solution to this 'problem' the hard way: ADODB (my favorite
database abstractionlayer) created errors in my application. When I
removed my own errorhandling the error were gone.
So I look at the line where the error originated, and they all had a @
in them. So I reread the whole errorhandling thingy on php.net, and it
actually says it quite clearly. But appearantly you missed it too.
Methinks the editors should put that part in BOLD. ;-)

Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 10 '08 #4
Erwin Moller wrote:
Hi,

Sorry to be so thick, but I do not understand what your problem is then.
Hehe, no worries, I may very well be the one who is thick here (in addition
to me putting on a few early Christmas pounds), because my whole problem is
basically that I don't understand the whole masking business :)
[quote]
You can overrule the default errorhandler (with its associated default
error_reporting levels) with you own customn errorhandler (with it
associated error_reporting levels passed to the function.).

This is your core 'problem', right?:
- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.
[/qoute]

So you pass a value to it for the mask:
(as defined here:
http://nl3.php.net/manual/en/functio...-reporting.php)
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
8192 E_DEPRECATED
16384 E_USER_DEPRECATED

So, for example, if you want to catch E_WARNING and E_NOTICE: you look
up their values, add them, and pass that value. In this case 2+8=12.
Yes, and now, because I don't believe (or, don't hope that) this is the
whole masking business. I'm thinking that the masking thing is a
bit-shifting thing that makes it possible to say yes please to E_WARNING
(2) and E_NOTICE (8), but NOT to E_PARSE (4), and thus it's not 2+8=10, but
some kind of shifting, which would explain the "squared leaps" in error
numbers instead of just 1,2,3,4,..., and also the "error_reporting =
E_ALL & ~E_NOTICE" which is definitely not a simple addition of error level
values.

That is my whole entire question. How does the masking business work? If
it's not just adding numbers, which I'm pretty sure it isn't :)

Daniel
But I have this feeling that I still don't understand what your problem
is. ;-)

<snip>
>>Also, if you write your own handler, be sure you check for
errorsupression.

Here is the first peice of code of an errorhandler I use often:

function errorHandler($number, $string, $file, $line, $context) {
// If the user uses errorsurperrsion with @, we need to forgive this
error!
if (error_reporting() == 0){
// The error was surpressed, return without futher interference.
return;
}
// rest of the errorhandler

I did not know of this. Very useful tip! I have previously turned
error_reporting on and off on-the-fly to achieve the same! Thank you very
much :)

Glad to hear that.
I found the solution to this 'problem' the hard way: ADODB (my favorite
database abstractionlayer) created errors in my application. When I
removed my own errorhandling the error were gone.
So I look at the line where the error originated, and they all had a @
in them. So I reread the whole errorhandling thingy on php.net, and it
actually says it quite clearly. But appearantly you missed it too.
Methinks the editors should put that part in BOLD. ;-)

Regards,
Erwin Moller

Nov 10 '08 #5
On Mon, 10 Nov 2008 23:09:56 +0100, da****@danielsmedegaardbuus.dk
wrote:[quote]
Erwin Moller wrote:
Hi,

Sorry to be so thick, but I do not understand what your problem is then.

Hehe, no worries, I may very well be the one who is thick here (in addition
to me putting on a few early Christmas pounds), because my whole problem is
basically that I don't understand the whole masking business :)
You can overrule the default errorhandler (with its associated default
error_reporting levels) with you own customn errorhandler (with it
associated error_reporting levels passed to the function.).

This is your core 'problem', right?:
- on every error/notice/whatever comes by my custom error handler, to be
able to specify a mask that essentially does the same only in my
set_error_handler call.
[/qoute]

So you pass a value to it for the mask:
(as defined here:
http://nl3.php.net/manual/en/functio...-reporting.php)
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
8192 E_DEPRECATED
16384 E_USER_DEPRECATED

So, for example, if you want to catch E_WARNING and E_NOTICE: you look
up their values, add them, and pass that value. In this case 2+8=12.

Yes, and now, because I don't believe (or, don't hope that) this is the
whole masking business. I'm thinking that the masking thing is a
bit-shifting thing that makes it possible to say yes please to E_WARNING
(2) and E_NOTICE (8), but NOT to E_PARSE (4), and thus it's not 2+8=10, but
some kind of shifting, which would explain the "squared leaps" in error
numbers instead of just 1,2,3,4,..., and also the "error_reporting =
E_ALL & ~E_NOTICE" which is definitely not a simple addition of error level
values.

That is my whole entire question. How does the masking business work? If
it's not just adding numbers, which I'm pretty sure it isn't :)
Right, the basic way to approach this is having each option assigned
a value of 2^n, which gives us binary numbers like:

00000001 OPTION_ONE
00000010 OPTION_TWO
00000100 OPTION_THREE
00001000 OPTION_FOUR
00010000 OPTION_FIVE
00100000 OPTION_SIX
01000000 OPTION_SEVEN
10000000 OPTION_EIGHT

You can increase the bit length as necessary. I chose to align each
of the values as a byte.

Using bit-wise operators is natural here for PHP. Depending on which
bits are "on", that will determine which error levels are being
employed. We use the bitwise operators to determine the combination
of 1's and 0's we want. The constants (E_*) are convenient, because
they provide context, and allow the confusing-looking values to
remain internalized, and possibly changed without affecting us. This
is why I would not recommend directly dealing with the values
themselves.

// Turning on multiple options via OR'ing bits together
$bitstring = E_ALL | E_STRICT;

Here's how you look at it in binary (aligning both to word length).
OR'ing results in a 1 if either bit is 1, 0 otherwise. Note that
E_ALL is essentially a shortcut for turning on several options, which
PHP has provided for us. Notice how the bit where E_STRICT is set is
0 in E_ALL. This shows why we need to OR E_STRICT explicitly.

0001 0111 1111 1111 (E_ALL = 6143 base 10)
OR
0000 1000 0000 0000 (E_STRICT = 2048 base 10)
-------------------
0001 1111 1111 1111 (E_ALL | E_STRICT = 8191 base 10)

I suggest you search for a tutorial on bitwise operations on the Web.
This concept is used fairly often in many languages.

[snip]

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Nov 11 '08 #6
Curtis wrote:
[quote]
On Mon, 10 Nov 2008 23:09:56 +0100, da****@danielsmedegaardbuus.dk
wrote:
>Erwin Moller wrote:
Hi,

Sorry to be so thick, but I do not understand what your problem is
then.

Hehe, no worries, I may very well be the one who is thick here (in
addition to me putting on a few early Christmas pounds), because my whole
problem is basically that I don't understand the whole masking business
:)
You can overrule the default errorhandler (with its associated default
error_reporting levels) with you own customn errorhandler (with it
associated error_reporting levels passed to the function.).

This is your core 'problem', right?:
- on every error/notice/whatever comes by my custom error handler, to
be
able to specify a mask that essentially does the same only in my
set_error_handler call.
[/qoute]

So you pass a value to it for the mask:
(as defined here:
http://nl3.php.net/manual/en/functio...-reporting.php)
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
8192 E_DEPRECATED
16384 E_USER_DEPRECATED

So, for example, if you want to catch E_WARNING and E_NOTICE: you look
up their values, add them, and pass that value. In this case 2+8=12.

Yes, and now, because I don't believe (or, don't hope that) this is the
whole masking business. I'm thinking that the masking thing is a
bit-shifting thing that makes it possible to say yes please to E_WARNING
(2) and E_NOTICE (8), but NOT to E_PARSE (4), and thus it's not 2+8=10,
but some kind of shifting, which would explain the "squared leaps" in
error
numbers instead of just 1,2,3,4,..., and also the "error_reporting =
E_ALL & ~E_NOTICE" which is definitely not a simple addition of error
level values.

That is my whole entire question. How does the masking business work? If
it's not just adding numbers, which I'm pretty sure it isn't :)

Right, the basic way to approach this is having each option assigned
a value of 2^n, which gives us binary numbers like:

00000001 OPTION_ONE
00000010 OPTION_TWO
00000100 OPTION_THREE
00001000 OPTION_FOUR
00010000 OPTION_FIVE
00100000 OPTION_SIX
01000000 OPTION_SEVEN
10000000 OPTION_EIGHT

You can increase the bit length as necessary. I chose to align each
of the values as a byte.

Using bit-wise operators is natural here for PHP. Depending on which
bits are "on", that will determine which error levels are being
employed. We use the bitwise operators to determine the combination
of 1's and 0's we want. The constants (E_*) are convenient, because
they provide context, and allow the confusing-looking values to
remain internalized, and possibly changed without affecting us. This
is why I would not recommend directly dealing with the values
themselves.

// Turning on multiple options via OR'ing bits together
$bitstring = E_ALL | E_STRICT;

Here's how you look at it in binary (aligning both to word length).
OR'ing results in a 1 if either bit is 1, 0 otherwise. Note that
E_ALL is essentially a shortcut for turning on several options, which
PHP has provided for us. Notice how the bit where E_STRICT is set is
0 in E_ALL. This shows why we need to OR E_STRICT explicitly.

0001 0111 1111 1111 (E_ALL = 6143 base 10)
OR
0000 1000 0000 0000 (E_STRICT = 2048 base 10)
-------------------
0001 1111 1111 1111 (E_ALL | E_STRICT = 8191 base 10)

I suggest you search for a tutorial on bitwise operations on the Web.
This concept is used fairly often in many languages.

[snip]
Ah, this was exactly what I was hoping for :) And easy to understand, too!
Thank you so much! :)

May I ask what the AND operator does? And the ~ in front of a constant, is
that only for the php.ini setting, or is that also valid in php, and if so,
what does it mean?

Thank you very much, Curtis, for the explanation :)

Daniel
Nov 11 '08 #7
On Tue, 11 Nov 2008 08:45:36 +0100, Daniel Smedegaard Buus
<da****@danielsmedegaardbuus.dkwrote in
<49***********************@news.sunsite.dk>:

[snip explanation of bit fields]
>May I ask what the AND operator does?
Assuming that you mean the "&" operator, it keeps only the bits that
are set in both variables. E.g. 2 & 3 = 2

00000010 // 2 base 2
00000011 // 3 base 2
--------
00000010 // keeps only the bit in the two's place
// because it's the only one set in both

>And the ~ in front of a constant, is that only for the php.ini
setting, or is that also valid in php, and if so, what does it mean?
It's the complement operator, which inverts the bits. E.g. if 2 is
00000010 then it's complement is 11111101. It's useful for removing a
bit from a bitfield. Saying E_ALL & ~ E_NOTICE is a way of saying
"everything except for notices".
--
Charles Calvert | Web-site Design/Development
Celtic Wolf, Inc. | Software Design/Development
http://www.celticwolf.com/ | Data Conversion
(703) 580-0210 | Project Management
Nov 11 '08 #8
On Tue, 11 Nov 2008 08:45:36 +0100, da****@danielsmedegaardbuus.dk
wrote:[quote]
Curtis wrote:
On Mon, 10 Nov 2008 23:09:56 +0100, da****@danielsmedegaardbuus.dk
wrote:
Erwin Moller wrote:

Hi,

Sorry to be so thick, but I do not understand what your problem is
then.

Hehe, no worries, I may very well be the one who is thick here (in
addition to me putting on a few early Christmas pounds), because my whole
problem is basically that I don't understand the whole masking business
:)

You can overrule the default errorhandler (with its associated default
error_reporting levels) with you own customn errorhandler (with it
associated error_reporting levels passed to the function.).

This is your core 'problem', right?:
- on every error/notice/whatever comes by my custom error handler, to
be
able to specify a mask that essentially does the same only in my
set_error_handler call.
[/qoute]

So you pass a value to it for the mask:
(as defined here:
http://nl3.php.net/manual/en/functio...-reporting.php)
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
6143 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
8192 E_DEPRECATED
16384 E_USER_DEPRECATED

So, for example, if you want to catch E_WARNING and E_NOTICE: you look
up their values, add them, and pass that value. In this case 2+8=12.


Yes, and now, because I don't believe (or, don't hope that) this is the
whole masking business. I'm thinking that the masking thing is a
bit-shifting thing that makes it possible to say yes please to E_WARNING
(2) and E_NOTICE (8), but NOT to E_PARSE (4), and thus it's not 2+8=10,
but some kind of shifting, which would explain the "squared leaps" in
error
numbers instead of just 1,2,3,4,..., and also the "error_reporting =
E_ALL & ~E_NOTICE" which is definitely not a simple addition of error
level values.

That is my whole entire question. How does the masking business work? If
it's not just adding numbers, which I'm pretty sure it isn't :)
[explanation snipped]
Ah, this was exactly what I was hoping for :) And easy to understand, too!
Thank you so much! :)

May I ask what the AND operator does? And the ~ in front of a constant, is
that only for the php.ini setting, or is that also valid in php, and if so,
what does it mean?

Thank you very much, Curtis, for the explanation :)

Daniel
I'm glad the explanation helped. :)

I'll leave you to read Charles Calvert's response on the bitwise &
and ~ (1's complement) operator.
--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Nov 12 '08 #9
Charles Calvert wrote:
On Tue, 11 Nov 2008 08:45:36 +0100, Daniel Smedegaard Buus
<da****@danielsmedegaardbuus.dkwrote in
<49***********************@news.sunsite.dk>:

[snip explanation of bit fields]
>>May I ask what the AND operator does?

Assuming that you mean the "&" operator, it keeps only the bits that
are set in both variables. E.g. 2 & 3 = 2

00000010 // 2 base 2
00000011 // 3 base 2
--------
00000010 // keeps only the bit in the two's place
// because it's the only one set in both

>>And the ~ in front of a constant, is that only for the php.ini
setting, or is that also valid in php, and if so, what does it mean?

It's the complement operator, which inverts the bits. E.g. if 2 is
00000010 then it's complement is 11111101. It's useful for removing a
bit from a bitfield. Saying E_ALL & ~ E_NOTICE is a way of saying
"everything except for notices".
Yes, thank you both :) I did the obligatory Googling, and ended up with an
extremely explanatory C tutorial on bitwise operations, and luckily, this
applies 1:1 on PHP :)

Funny, from the outside it seems like a bad thing to be happy that you just
made handling of errors in your code faster ;) He he. Well, we gotta be
realistic beings, right? ;)

Another funny thing is that reading this, everything just fell into place.
I've been taught this as part of my education, specifically when learning
assembly language, but for some reason it just doesn't stick with me... I
really like languages like Ruby :D

Either way, It's great to revisit basic stuff like this, because it really
adds a lot of understanding to knowing what you're actually doing when you
declare a class or use something basic like control structures. It's really
healthy to learn this, you know :)

Cheers to you both,
Daniel :)
Nov 12 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Marty McDonald | last post by:
If I invoke a web service, and it throws an exception, I can see the exception if the client app is a .Net app. However, if the client app is not a .Net app, I only receive the HTTP 500 error. I...
2
by: Ginchy | last post by:
I have uploaded a small 3 page web using MS Publisher 2003 and after uploading I switched on url masking to cloak the url. I am certain that it worked fine. I simply changed the colour scheme...
2
by: Richard Gooding | last post by:
Hi, I have some code that I run in a JSP that breaks with the above error, but works ok in a standalone Java Program. Could this be a bug in DB2 / JDBC ? I've installed the latest DB2 fixpack...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
7
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3...
3
by: Ted | last post by:
Please consider the following example. CREATE TABLE test ( an_ndx int NOT NULL primary key identity(1,1), a_var varchar(48) NOT NULL, last_edit_timestamp datetime NOT NULL default...
29
by: mailforpr | last post by:
Sometimes, I can't think of any good reason why I should have the program's logic thrown an exception. Except for catching the exception and printing "Uh, oh" to the screen. I also think that in...
1
by: hapa | last post by:
how can i use bitwise masking in C++ please explain
1
by: kommaraju | last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2 using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a error message of HTTP STATUS 500 my jdbc...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.