|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69275 SplFileObject constructor cannot be overridden
Submitted: 2015-03-22 07:41 UTC Modified: 2015-03-24 05:44 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: stephen dot reay at me dot com Assigned: danack (profile)
Status: Assigned Package: *General Issues
PHP Version: 5.6.7 OS: OS X, Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-03-22 07:41 UTC] stephen dot reay at me dot com
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:

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');



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


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-22 19:23 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: danack
 [2015-03-22 19:23 UTC]
The cause is pretty clear. When the class is the standard SplFileObject the parameters passed to openFile are read and passed to the file open call.

When the class isn't that class, the params aren't parsed and instead the mode is set to 'r' only:

Which obviously causes the file opening to fail, as the file doesn't exist.
 [2015-03-24 05:44 UTC]
@danack are you able to make a patch? thanks
 [2015-03-24 13:15 UTC]
I'm looking at it yes.

Whether I'm able to fix it, is a question yet to be determined.
 [2015-03-24 19:51 UTC]
PR is attached - as it changes the Zend engine to allow functions that contain more than 2 parameters to be easily callable, it needs some more eyes on it.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC