Bug #72542 [NEW]: SplFileObject::getCurrentLine() is not an alias of ::fgets()
From: cmb
Operating system: *
PHP version: 7.0.8
Package: SPL related
Bug Type: Bug
Bug description:SplFileObject::getCurrentLine() is not an alias of ::fgets()
Description:
------------
The documentation of SplFileObject::getCurrentLine()[1] states
that this method is an alias of SplFileObject::fgets(). However,
that doesn't seem to be the case.
If the method was a true alias, it shouldn't matter whether we
override ::getCurrentLine() or ::fgets() by simply calling the
parent method, but the reported key()s differ (actually,
MyBadFileObject skips every other line number).
I've reported the bug against the latest current stable PHP, but
the behavior is the same for all versions I've tested.
The supplied test script is longer than the postulated 20 lines,
but in my opinion it is easier to read this way.
[1] <http://php.net/manual/en/splfileobject.getcurrentline.php>
Test script:
---------------
<?php
class MyGoodFileObject extends SplFileObject {
public function fgets() {
return parent::fgets();
}
}
class MyBadFileObject extends SplFileObject {
public function getCurrentLine() {
return parent::getCurrentLine();
}
}
function iterateWith($class) {
$file = new $class(__FILE__);
$i = 0;
foreach ($file as $line) {
echo $file->key(), ' ', $file->current();
if ($i++ >= 3) break;
}
echo PHP_EOL;
}
iterateWith('MyGoodFileObject');
echo '---------------', PHP_EOL;
iterateWith('MyBadFileObject');
Expected result:
----------------
0 <?php
1
2 class MyGoodFileObject extends SplFileObject {
3 public function fgets() {
---------------
0 <?php
1
2 class MyGoodFileObject extends SplFileObject {
3 public function fgets() {
Actual result:
--------------
0 <?php
1
2 class MyGoodFileObject extends SplFileObject {
3 public function fgets() {
---------------
1 <?php
3
5 class MyGoodFileObject extends SplFileObject {
7 public function fgets() {
--
Edit bug report at https://bugs.php.net/bug.php?id=72542&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72542&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72542&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72542&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72542&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72542&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72542&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72542&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72542&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72542&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72542&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72542&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72542&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72542&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72542&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72542&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72542&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72542&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72542&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72542&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72542&r=mysqlcfg
Thread (1 message)
- cmb@php.net