From:             jr at terragate dot net
Operating system: Mac OS X 10.4.1
PHP version:      5CVS-2005-06-15 (dev)
PHP Bug Type:     SPL related
Bug description:  SPL throws E_STRICT warnings as exceptions

Description:
------------
Currently SPL sets the error_handling to EH_THROW which will 
cause any E_WARNING or E_STRICT message to be thrown as 
exception regardless of error_reporting's settings.

This renders most code with compatibility in mind (e.g. 
PEAR) useless in SPL context since there is no way to ignore 
non fatal warnings.

At least E_STRICT messages shouldn't be thrown if it is 
disabled in error_reporting. 

But this might still be confusing. E_STRICT massages should 
be treated as compile time warnings (as in most other 
languages). They shouln't affect the control flow if not 
explicitly requested.

Generally the same applies to E_WARNING and E_USER_WARNING 
as long as there is no way to disable EH_THROW in user space 
php code.   

IMHO EH_THROW should be completly disabled or the error mode 
should be made controlable:

// ignore warnings from this wrapper
error_mode(EH_NORMAL);
$it = new DirectoryIterator('legacywrapper://path/');

// I want to stop on some warnings
error_mode(EH_THROW);
try {
  $it = new DirectoryIterator('legacywrapper://path/');
} catch(Exception $e) {
  // parse exception which might contain an E_WARNING 
message 
  // this is not really OO but it works
  ...
  if($criticalWarning) {
    // bail out
    throw new AMoreAppropriateException();
  } else { 
    // non critical warning trying again with EH_NORMAL
    // using normal php error/warning handling here
    ...
  }
}

As long as all warnings are thrown as 'Exception' the 
EH_THROW mode can't be used as different warnings cannot be 
easily distinguished.






Reproduce code:
---------------
<?php

error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);

class StreamWrapper
{
  public function dir_opendir($path, $options) {
    return !is_a(null, 'AKnownOrUnknownClass');
  }

  public function dir_readdir() {
    return array();
  }

}

stream_wrapper_register('test', 'StreamWrapper');


echo "Done\n";

?>


Expected result:
----------------
Output of "Done"

Actual result:
--------------
Fatal error: Uncaught exception 'Exception' with message 'is_a
(): Deprecated. Please use the instanceof operator' in /Users/
reith2/Projects/php/bug-new.php:8
Stack trace:
#0 /Users/reith2/Projects/php/bug-new.php(8): is_a(NULL, 
'AKnownOrUnknown...')
#1 /Users/reith2/Projects/php/bug-new.php(18): StreamWrapper-
>dir_opendir('test://path/', 4)
#2 /Users/reith2/Projects/php/bug-new.php(18): 
DirectoryIterator->__construct('test://path/')
#3 {main}


-- 
Edit bug report at http://bugs.php.net/?id=33355&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33355&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33355&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33355&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33355&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33355&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33355&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33355&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33355&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33355&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33355&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33355&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33355&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33355&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33355&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33355&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33355&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33355&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33355&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33355&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33355&r=mysqlcfg

Reply via email to