Bug #69275 [NEW]: SplFileObject constructor cannot be overridden
From: stephen dot reay at me dot com
Operating system: OS X, Linux
PHP version: 5.6.7
Package: *General Issues
Bug Type: Bug
Bug description:SplFileObject constructor cannot be overridden
Description:
------------
A class that extends SplFileObject, specifies its own constructor and
is registered with SplFileInfo::setFileClass() will only be instantiated
with the first argument passed to SplFileInfo::openFile().
Test script:
---------------
<?php
class FileObject extends \SplFileObject {
public function __construct($file_name, $open_mode = 'r',
$use_include_path = false, $context = null) {
if (is_resource($context)) {
parent::__construct($file_name, $open_mode, $use_include_path,
$context);
}
else {
parent::__construct($file_name, $open_mode, $use_include_path);
}
}
}
$file = new \SplFileInfo(__DIR__ . DIRECTORY_SEPARATOR . 'foo');
$file->setFileClass('FileObject');
$file->openFile('w+');
Expected result:
----------------
File is created
Actual result:
--------------
Fatal error: Uncaught exception 'RuntimeException' with message
'SplFileObject::__construct(/Users/stephen/Projects/Koalephant/Bamboo/tests/foo):
failed to open stream: No such file or directory' in
/Users/stephen/Projects/Koalephant/Bamboo/tests/SplFileInfoTest.php:10
Stack trace:
#0
/Users/stephen/Projects/Koalephant/Bamboo/tests/SplFileInfoTest.php(10):
SplFileObject->__construct('/Users/stephen/...', 'r', false)
#1 [internal function]: FileObject->__construct('/Users/stephen/...',
'r')
#2
/Users/stephen/Projects/Koalephant/Bamboo/tests/SplFileInfoTest.php(19):
SplFileInfo->openFile('w+')
#3 {main}
thrown in
/Users/stephen/Projects/Koalephant/Bamboo/tests/SplFileInfoTest.php on
line 10
--
Edit bug report at https://bugs.php.net/bug.php?id=69275&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69275&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69275&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69275&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69275&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69275&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69275&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69275&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69275&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69275&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69275&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69275&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69275&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69275&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69275&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69275&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69275&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69275&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69275&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69275&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69275&r=mysqlcfg
Thread (7 messages)
- stephen dot reay at me dot com