From:
Operating system:
PHP version: 5.3.5
Package: SPL related
Bug Type: Bug
Bug description:RangeException and OutOfRangeException extend invalid classes
Description:
------------
This is a rather minor problem. SPL defines two base exception classes:
LogicException for reporting problems with various
system/component/class/argument logic and RuntimeException for runtime
problems. LogicException is extended by a number of classes:
- DomainException
- InvalidArgumentException
- LengthException (entered length is not a valid length)
RuntimeException is extended by:
- OutOfBoundsException (value out of bounds)
- UnexpectedValueException (value was not expected)
- OverflowException
- UnderflowException
As we see, the problems with tested values are classified as runtime
exceptions, and problems with specifying constrains are classified as logic
exceptions. However, this is not true in case of RangeException and
OutOfRangeException, where the base classes are replaced:
- RangeException (constraint range is invalid) is RuntimeException, should
be: LogicException*
- OutOfRangeException (value is out of range) is LogicException, should be:
RuntimeException
* - Actually, the first version can be considered as runtime exception,
too, if the user has to enter some range, but then it should be clearly
pointed out in the documentation. However, the second exception is
definitely wrong.
There can be also an issue that I misunderstood the documentation, but in
this case the problem should be reclassified as a documentation problem,
and concern providing more information about the semantically correct usage
of the provided exceptions. Currently, the documentation provides only a
single and often very abstract sentence which results in many
misunderstandings - if you are interested, I can provide a translation of
the discussion I've recently found to show that the way people are using
and understanding these classes is very far away from authors' intentions.
So, to sum up: either these classes extend invalid base classes, or the
documentation should be MUCH more precise here.
Test script:
---------------
<?php
// Assume we are sending the invalid age, i.e. "10"
try
{
if($_POST['age'] < 13 || $_POST['age'] > 100)
{
throw new OutOfRangeException('The specified age is not within the
accepted range 13 to 100 years.');
}
}
catch(RuntimeException $exception)
{
echo 'Oops, you entered wrong data. Please correct them!';
}
catch(LogicException $exception)
{
echo 'There is a problem with the system. Please contact the
administrator.';
}
Expected result:
----------------
Oops, you entered wrong data. Please correct them!
Actual result:
--------------
There is a problem with the system. Please contact the administrator.
--
Edit bug report at http://bugs.php.net/bug.php?id=53806&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53806&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53806&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53806&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53806&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53806&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53806&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53806&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53806&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53806&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53806&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53806&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53806&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53806&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53806&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53806&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53806&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53806&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53806&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53806&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53806&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53806&r=mysqlcfg