Req #51532 [Opn->Csd]: Cannot override SplFileObject::fscanf()
| From: | colder@php.net | Date: | Sun, 25 Apr 2010 05:19:38 +0000 |
| Subject: | Req #51532 [Opn->Csd]: Cannot override SplFileObject::fscanf() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-149858@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51532&edit=1
ID: 51532
Updated by: colder@php.net
Reported by: mi dot olszewski at gmail dot com
Summary: Cannot override SplFileObject::fscanf()
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: SPL related
Operating System: MS Windows Vista
PHP Version: 5.3.2
-Assigned To:
+Assigned To: colder
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-04-25 07:18:44] 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-11 15:14:23] 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()
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51532&edit=1