: Request #51532 :: Cannot override SplFileObject::fscanf()
| 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 | ||
[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 commits
[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