|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51532 Cannot override SplFileObject::fscanf()
Submitted: 2010-04-11 15:14 UTC Modified: 2010-04-25 07:19 UTC
From: mi dot olszewski at gmail dot com Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.2 OS: MS Windows Vista
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mi dot olszewski at gmail dot com
New email:
PHP Version: OS:


 [2010-04-11 15:14 UTC] mi dot olszewski at gmail dot com
There seems to be a problem with overriding SPLFileObject::fscanf() method. I'm not sure whether this is PHP language-related issue or issue with method definition in SPLFileObject.

When you look at '' file from PHP 5.3.2 source code you can see that method definition is:

function fscanf($format /* , ... */)

so it seems logical to assume only one parameter in overridden method.

However, using Reflection API to get fscanf parameters:

$class = new ReflectionClass('SPLFileObject');
$method = $class->getMethod('fscanf');
$params = $method->getParameters();
foreach ($params as $p)
 echo $p->getName() . PHP_EOL;

Prints out:


Yes - '...' is literally printed out.

So it leaves me puzzled - either I am missing something very obvious or fscanf is handling variable-length method arguments in some non-standard way (like using func_get_args()).

All in all - overriding fscanf in a way like in specified example test script results in strict standards notice.

Test script:
class SomeOtherFileObject extends SPLFileObject {
  function fscanf($format) {
    echo 'my little dummy';

$test = new SomeOtherFileObject('test.php');

Expected result:
The fscanf method is overridden without PHP notices, warnings and errors.

Actual result:
Strict standards: Declaration of SomeOtherFileObject::fscanf() should be compatible with that of SplFileObject::fscanf()


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-25 07:18 UTC]
Automatic comment from SVN on behalf of colder
Log: Fix #51532 (Invalid prototype for SplFileInfo::fscanf)
 [2010-04-25 07:19 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: colder
 [2010-04-25 07:19 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2010-04-27 07:03 UTC]
Automatic comment from SVN on behalf of colder
Log: Merge fix for #51532
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 03:01:24 2020 UTC