Bug #55701 [Com]: GlobIterator throws LogicException with message 'The parent constructor was not

From: Date: Mon, 11 Jan 2016 16:24:10 +0000
Subject: Bug #55701 [Com]: GlobIterator throws LogicException with message 'The parent constructor was not
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198574@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55701&edit=1

 ID:                 55701
 Comment by:         pheagey at gmail dot com
 Reported by:        bs@php.net
 Summary:            GlobIterator throws LogicException with message 'The
                     parent constructor was not
 Status:             Assigned
 Type:               Bug
 Package:            SPL related
 Operating System:   Linux, OSX
 PHP Version:        5.3.8
 Assigned To:        cataphract
 Block user comment: N
 Private report:     N

 New Comment:

Able to reproduce error in 5.5.6 on Ubuuntu 14.04

$iterator = new GlobIterator('./someDir/*');
$iterator->count();

Where 'someDir' has not contents.


Previous Comments:
------------------------------------------------------------------------
[2014-08-10 10:57:12] hanskrentel at yahoo dot de

Additionally I can not reproduce the original report:

-----------------------------------------------------
<?php

$g = new \GlobIterator(__DIR__ . '/*');

do {
    $g->next();
} while($g->valid());

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

Works flawlessly for me. Using 5.5.15

------------------------------------------------------------------------
[2014-08-10 10:53:44] hanskrentel at yahoo dot de

SplFileObject checks on method invocation that the state is sane - it does not care whether or not
you have it extended.

Whether or not this qualifies as a bug (I tend to say it isn't a flaw, because SplFileObject
has it's responsibilities and if you extend from it, you're explicitly stating that your
object comes with the same responsibilities, you can not lower the checks).

However, if you actually want to stub the file-object first, that must not stand in your way,
it's easy to work-around, for example with a fake "data://" URI:

<?php
/*
 * File: test.php
 * Link: https://bugs.php.net/bug.php?id=55701
 */

class MyFileObject extends \SplFileObject
{
    public function __construct($file_name)
    {
        parent::__construct("data://,");

        $new_fname = $this->getRealPath();

        parent::__construct($file_name);
    }

    public function getRealPath()
    {
        return '/tmp/foo.txt';
    }
}

$f1 = new MyFileObject(__FILE__);

var_dump($f1->getBasename()); # string(8) "test.php"

------------------------------------------------------------------------
[2014-02-26 14:11:20] log dot kot at gmail dot com

Confirm the bug

Ubuntu Linux 13.10 3.11.0-17-generic x86_64

PHP 5.5.3-1ubuntu2.1 (cli) (built: Dec 12 2013 04:24:35) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

------------------------------------------------------------------------
[2013-08-02 11:54:52] rosier at interstroom dot nl

I can confirm this unexpected result also for php54 and php55

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

$path_to_files = sys_get_temp_dir();

// Next works as expected: no xml files found = no output
foreach (new GlobIterator($path_to_files . '/*.xml') as $fileinfo) {
    echo $fileinfo->getFilename() . "\n";
}

$it = new GlobIterator($path_to_files . '/*.xml');
// Expected result: count = 0
// Instead next line will crash php if no xml files are found
if ($it->count()) {
    // do something...
}

?>

------------------------------------------------------------------------
[2013-01-28 07:38:40] sergei dot solomonov at gmail dot com

I have same problem too.
OS: windows 7 x64, PHP 5.4.7 (built: Sep 12 2012 23:48:31).
I working with ZF2, when I trying to use phar-packed modules same error occured.
But in Ubuntu works fine.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=55701


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


Thread (13 messages)

« previous php.bugs (#198574) next »