Bug #55701 [Asn->Csd]: GlobIterator throws LogicException

From: Date: Tue, 05 Jul 2016 14:57:50 +0000
Subject: Bug #55701 [Asn->Csd]: GlobIterator throws LogicException
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202072@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 Updated by: cmb@php.net Reported by: bs@php.net Summary: GlobIterator throws LogicException -Status: Assigned +Status: Closed Type: Bug Package: SPL related Operating System: Linux, OSX PHP Version: 5.3.8 Assigned To: cmb Block user comment: N Private report: N New Comment: Automatic comment on behalf of axiac.ro@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=4c24f170ea3701c9aadde6c575a777ee4027f463 Log: Fix bug #55701: GlobIterator throws LogicException Previous Comments: ------------------------------------------------------------------------ [2016-07-05 13:49:02] cmb@php.net I can confirm this behavior with current master. > This happens when the method is used in constructor prior to > calling the parent constructor even if the trait method is > aliased […] As hanskrentel already explained, this doesn't appear to be a bug. Anyhow, it's not related to this very issue, so feel free to file another ticket. ------------------------------------------------------------------------ [2016-02-08 10:30:39] axiac dot ro at gmail dot com Tested on PHP 5.3, 5.4, 5.5, 5.6 and 7.0 on OSX and Ubuntu. It fails the same on all of them. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $g = new \GlobIterator('/tmp/*.txt'); echo('Before: '.$g->count()."\n"); foreach ($g as $f) { } echo('After : '.$g->count()."\n"); If the glob expression matches at least one file it throws the exception on the second call to count() (line 9). If it doesn't match then it throws on the first call to count() (line 6). Not only count() throws the exception. All its methods do the same. ------------------------------------------------------------------------ [2016-01-11 16:24:08] pheagey at gmail dot com Able to reproduce error in 5.5.6 on Ubuuntu 14.04 $iterator = new GlobIterator('./someDir/*'); $iterator->count(); Where 'someDir' has not contents. ------------------------------------------------------------------------ [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" ------------------------------------------------------------------------ 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

« previous php.bugs (#202072) next »