php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63246 SplFileObject::__construct() example showing code in expected output box.
Submitted: 2012-10-09 10:39 UTC Modified: 2012-10-09 15:44 UTC
From: simon dot champion at connectionservices dot com Assigned: salathe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-10-09 10:39 UTC] simon dot champion at connectionservices dot com
Description:
------------
---
From manual page: http://www.php.net/splfileobject.construct#refsect1-splfileobject.construct-examples
---

Example #1 SplFileObject::__construct() example

In this example, the "expected output" box is currently showing the code, not the output (ie it is identical to the box above it containing the code).



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-09 12:00 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2012-10-09 12:00 UTC] salathe@php.net
As the page states, "This example opens the current file and iterates over its 
contents line by line."

The whole point of that example is to open the file containing the example code 
and echo each line one by one.
 [2012-10-09 12:22 UTC] simon dot champion at connectionservices dot com
Sorry: my point was not that the example is incorrect, but that it's unclear. Sorry if I didn't express that well.

I believe it could be improved by adding something (for example line numbers) to the output. This would make it clearer that it is the result of the code being run rather than simply a copy of the original source code.

This is what I would suggest:

<?php
$file = new SplFileObject(__FILE__);
foreach ($file as $lineNum=>$line) {
    echo "Line # " . $lineNum . ": " . $line;
}
?>
 [2012-10-09 13:02 UTC] salathe@php.net
That is true, the example could be improved to better avoid confusion.
 [2012-10-09 13:02 UTC] salathe@php.net
-Status: Not a bug +Status: Assigned -Assigned To: +Assigned To: salathe
 [2012-10-09 15:44 UTC] salathe@php.net
-Status: Assigned +Status: Closed
 [2012-10-09 15:44 UTC] salathe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 19:00:01 2026 UTC