php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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 'splfileobject.inc' 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:

format
...

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');
$test->fscanf('%s');

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()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-25 07:18 UTC] colder@php.net
Automatic comment from SVN on behalf of colder
Revision: http://svn.php.net/viewvc/?view=revision&revision=298475
Log: Fix #51532 (Invalid prototype for SplFileInfo::fscanf)
 [2010-04-25 07:19 UTC] colder@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: colder
 [2010-04-25 07:19 UTC] colder@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-04-27 07:03 UTC] colder@php.net
Automatic comment from SVN on behalf of colder
Revision: http://svn.php.net/viewvc/?view=revision&revision=298635
Log: Merge fix for #51532
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC