Edit report at https://bugs.php.net/bug.php?id=55300&edit=1

 ID:                 55300
 Updated by:         cataphr...@php.net
 Reported by:        frederic dot hardy at mageekbox dot net
 Summary:            \DirectoryIterator, parent::__construct() and
                     \LogicException
 Status:             Open
 Type:               Bug
 Package:            SPL related
 Operating System:   Linux
 PHP Version:        5.4.0alpha2
 Block user comment: N
 Private report:     N

 New Comment:

Why can't you use a user stream wrapper then? Maybe DirectoryIterator should be 
an interface, but it isn't.


Previous Comments:
------------------------------------------------------------------------
[2011-07-28 07:27:19] frederic dot hardy at mageekbox dot net

This bug seems to be related to #54384.
And i want to do this to mock a \DirectoryIterator instance, to "simulate" a 
directory on the file system.

------------------------------------------------------------------------
[2011-07-27 23:30:06] cataphr...@php.net

If you don't call the parent constructor, the class has no functionality. Why 
would you want to do this?

------------------------------------------------------------------------
[2011-07-27 15:36:56] frederic dot hardy at mageekbox dot net

Description:
------------
In PHP 5.4, an exception was throwed if a call to parent::__construct() is not 
done in the constructor of a class which extends \DirectoryIterator.
Exception was not throwed in previous version of PHP, so it's a BC break.
And this BC break must be annoying in unit test, because it's impossible to 
mock the \DirectoryIterator class.

Test script:
---------------
<?php

class myDirectoryIterator extends \DirectoryIterator
{
        public function __construct()
        {
        }
}

$directoryIterator = new myDirectoryIterator();

?>

Expected result:
----------------
Nothing.

Actual result:
--------------
Fatal error: Uncaught exception 'LogicException' with message 'In the 
constructor of myDirectoryIterator, parent::__construct() must be called and 
its exceptions cannot be cleared' in /path/to/directoryIterator.php:10
Stack trace:
#0 /path/to/directoryIterator.php(10): 
myDirectoryIterator->internal_construction_wrapper()
#1 {main}
  thrown in /path/to/directoryIterator.php on line 10



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55300&edit=1

Reply via email to