Re: [PHP] require_once and E_WARNING?

2006-07-06 Thread Martin Marques

On Wed, 5 Jul 2006, [EMAIL PROTECTED] wrote:


Hello all,

According to the PHP Manual, when require or require_once failes, an
E_ERROR is triggered: require() and include()  are identical in every way
except how they handle failure. include() produces a Warning while
require() results in a  Fatal Error. (With 'Fatal Error' being a link to
E_ERROR).

Thing is, when using a custom error handler via set_error_handler(), it
appears to be triggering an E_WARNING, not an E_ERROR. Using PHP 5.1.4
under Linux.

There are one of three possibilities: I am suffering from a lapse in
lucidity (common), the manual is wrong (possible), or PHP is broken
somehow (unlikely). I'm guessing it's the first, but what am I doing
wrong? I'd like to get a second opinion before submitting a bug. I
searched bugs.php.net but was unable to find anything relevant for 5.1.4.

Code:
function default_error_handler($code, $error, $file, $line) {
  switch ($code) {
  case E_ERROR:
 die (Error: $error);
  case E_WARNING:
 die(Warning: $error);
  default:
 die(Something else entirely: $error);
  }
}


What happens if you put breaks after the die()? This shouldn't be 
necesary, but it wouldn't hurt to try. ;-)


As I see in the example of the PHP manual, a break is put even after an 
exit(1) call.



set_error_handler('default_error_handler');
require('This file does not exist. At least not here!');


Have you tried this handler with something more fatal, like a missing 
semi-colon or a } missmatch?


--
 21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
-
Lic. Martín Marqués |   SELECT 'mmarques' ||
Centro de Telemática|   '@' || 'unl.edu.ar';
Universidad Nacional|   DBA, Programador,
del Litoral |   Administrador
-
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] require_once and E_WARNING?

2006-07-06 Thread chris smith

On 7/6/06, Martin Marques martin@bugs.unl.edu.ar wrote:

On Wed, 5 Jul 2006, [EMAIL PROTECTED] wrote:

 Hello all,

 According to the PHP Manual, when require or require_once failes, an
 E_ERROR is triggered: require() and include()  are identical in every way
 except how they handle failure. include() produces a Warning while
 require() results in a  Fatal Error. (With 'Fatal Error' being a link to
 E_ERROR).

 Thing is, when using a custom error handler via set_error_handler(), it
 appears to be triggering an E_WARNING, not an E_ERROR. Using PHP 5.1.4
 under Linux.

 There are one of three possibilities: I am suffering from a lapse in
 lucidity (common), the manual is wrong (possible), or PHP is broken
 somehow (unlikely). I'm guessing it's the first, but what am I doing
 wrong? I'd like to get a second opinion before submitting a bug. I
 searched bugs.php.net but was unable to find anything relevant for 5.1.4.

 Code:
 function default_error_handler($code, $error, $file, $line) {
   switch ($code) {
   case E_ERROR:
  die (Error: $error);
   case E_WARNING:
  die(Warning: $error);
   default:
  die(Something else entirely: $error);
   }
 }

What happens if you put breaks after the die()? This shouldn't be
necesary, but it wouldn't hurt to try. ;-)

As I see in the example of the PHP manual, a break is put even after an
exit(1) call.

 set_error_handler('default_error_handler');
 require('This file does not exist. At least not here!');

Have you tried this handler with something more fatal, like a missing
semi-colon or a } missmatch?


That will cause a parse error and the script won't even run.

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] require_once and E_WARNING?

2006-07-06 Thread Jochem Maas
chris smith wrote:
 On 7/6/06, Martin Marques martin@bugs.unl.edu.ar wrote:
 On Wed, 5 Jul 2006, [EMAIL PROTECTED] wrote:

  Hello all,
 
  According to the PHP Manual, when require or require_once failes, an
  E_ERROR is triggered: require() and include()  are identical in
 every way
  except how they handle failure. include() produces a Warning while
  require() results in a  Fatal Error. (With 'Fatal Error' being a
 link to
  E_ERROR).
 
  Thing is, when using a custom error handler via set_error_handler(), it
  appears to be triggering an E_WARNING, not an E_ERROR. Using PHP 5.1.4
  under Linux.
 
  There are one of three possibilities: I am suffering from a lapse in
  lucidity (common), the manual is wrong (possible), or PHP is broken
  somehow (unlikely). I'm guessing it's the first, but what am I doing
  wrong? I'd like to get a second opinion before submitting a bug. I
  searched bugs.php.net but was unable to find anything relevant for
 5.1.4.
 
  Code:
  function default_error_handler($code, $error, $file, $line) {
switch ($code) {
case E_ERROR:
   die (Error: $error);
case E_WARNING:
   die(Warning: $error);
default:
   die(Something else entirely: $error);
}
  }

 What happens if you put breaks after the die()? This shouldn't be
 necesary, but it wouldn't hurt to try. ;-)

 As I see in the example of the PHP manual, a break is put even after an
 exit(1) call.

  set_error_handler('default_error_handler');
  require('This file does not exist. At least not here!');

 Have you tried this handler with something more fatal, like a missing
 semi-colon or a } missmatch?
 
 That will cause a parse error and the script won't even run.

try it with a call to an undefined function e.g.:

$foo = thisFunctionDoesNotExistAtLeastItHadBetterNot();

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] require_once and E_WARNING?

2006-07-06 Thread Martin Marques

On Thu, 6 Jul 2006, chris smith wrote:



Have you tried this handler with something more fatal, like a missing
semi-colon or a } missmatch?


That will cause a parse error and the script won't even run.


You're right. My wrong. :-(

--
 21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
-
Lic. Martín Marqués |   SELECT 'mmarques' ||
Centro de Telemática|   '@' || 'unl.edu.ar';
Universidad Nacional|   DBA, Programador,
del Litoral |   Administrador
-
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] require_once and E_WARNING?

2006-07-06 Thread KermodeBear

chris smith wrote:
 try it with a call to an undefined function e.g.:
 $foo = thisFunctionDoesNotExistAtLeastItHadBetterNot();

When this is done, the error handler doesn't get called at all, and the
script simply dies with an error message (which could be a bug as well, but
might also be considered a 'parse error' even if it happens at runtime; I
doubt they would fix it).

I read through the set_error_handler() documentation again though, and I
found that:  The following error types cannot be handled with a user
defined function: E_ERROR[...]

So, I'm guessing that the require() functions raise an E_WARNING before the
E_ERROR. Seems odd. Perhaps what happens under the hood is that require()
calls include(), which would raise an E_WARNING when it fails, then the
require() code checks the result of include() and if it failed then it
raises the E_ERROR.

It pays to RTFM more closely, it seems. (o;  My bad.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] require_once and E_WARNING?

2006-07-05 Thread Chris

[EMAIL PROTECTED] wrote:

Hello all,

According to the PHP Manual, when require or require_once failes, an
E_ERROR is triggered: require() and include()  are identical in every way
except how they handle failure. include() produces a Warning while
require() results in a  Fatal Error. (With 'Fatal Error' being a link to
E_ERROR).

Thing is, when using a custom error handler via set_error_handler(), it
appears to be triggering an E_WARNING, not an E_ERROR. Using PHP 5.1.4
under Linux.

There are one of three possibilities: I am suffering from a lapse in
lucidity (common), the manual is wrong (possible), or PHP is broken
somehow (unlikely). I'm guessing it's the first, but what am I doing
wrong? I'd like to get a second opinion before submitting a bug. I
searched bugs.php.net but was unable to find anything relevant for 5.1.4.

Code:
function default_error_handler($code, $error, $file, $line) {
   switch ($code) {
   case E_ERROR:
  die (Error: $error);
   case E_WARNING:
  die(Warning: $error);
   default:
  die(Something else entirely: $error);
   }
}
set_error_handler('default_error_handler');
require('This file does not exist. At least not here!');

Result:
Warning: require(This file does not exist. At least not here!)
[function.require]: failed to open stream: No such file or directory

Expected Result:
Error: require(This file does not exist. At least not here!)
[function.require]: failed to open stream: No such file or directory



If you comment out the 'set_error_handler' line what happens? Do you get 
what you expect (and what should happen) ?


It looks like a pretty simple bug report to me but others may have 
reasons why it's not working.


--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] require_once and E_WARNING?

2006-07-05 Thread php
 Code:
 function default_error_handler($code, $error, $file, $line) {
switch ($code) {
case E_ERROR:
   die (Error: $error);
case E_WARNING:
   die(Warning: $error);
default:
   die(Something else entirely: $error);
}
 }
 set_error_handler('default_error_handler');
 require('This file does not exist. At least not here!');

 Result:
 Warning: require(This file does not exist. At least not here!)
 [function.require]: failed to open stream: No such file or directory

 Expected Result:
 Error: require(This file does not exist. At least not here!)
 [function.require]: failed to open stream: No such file or directory


 If you comment out the 'set_error_handler' line what happens? Do you get
 what you expect (and what should happen) ?

 It looks like a pretty simple bug report to me but others may have
 reasons why it's not working.

Without the error handler, I get the expected result: A fatal error with
the script dying. That is what makes this so mysterious. Doesn't make
sense that it would raise a different kind of error under different
circumstances. It should have the same value every time.

I'm going to sit on this for a day or so and see what people say before I
toss it over to the bug folks. No sense in bothering them if I'm being a
bonehead. (o;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php