Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:43:49+00:00 2026-05-17T19:43:49+00:00

PHP5 introduced an object-oriented file wrapper, SplFileObject . I guess I just found out

  • 0

PHP5 introduced an object-oriented file wrapper, SplFileObject. I guess I just found out why hardly anybody is using it. It’s purely line-oriented, there is no fread() method – which the corresponding frwite seemed to suggest.

So now I’m wondering if I can extend it. I’m however not sure what’s the better workaround. SplFileObject is not particular helpful in tucking the file pointer ($fp) away – it’s either a private attribute or ZE-internal resource. So how would I extend it to get a fread method?

  • Implement fread() as string collecting loop with fgets(), with eventual seeking if only a specific size was requested and fgets read too far until the next \n line break.
  • Use a custom constructor, which opens the file a second time and stores a secondary file pointer, in case I want to call fread() instead of the parent class methods.

I’d go for the fgets workaround loop, but it sounds cumbersome and slow and provides for more potential pitfalls. OTOH opening a secondary file pointer seems not a good approach either and needs a custom destructor too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:43:50+00:00Added an answer on May 17, 2026 at 7:43 pm

    You can call extend it and add an fread method that calls the fgetc method repeatedly, the desired number of times.

    That said, I agree this is a weird limitation. Submit a feature request. If I’m not missing something, and fread method ought to be implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP5.2.x back end. The text data transfer is using JSON objects. Am looking at
In PHP5, is the __destruct() method guaranteed to be called for each object instance?
If you are using php5 and mysql5, is there a substantial advantage to using
I'm using PHP5 to create XML files. I have code like this: $doc =
How would one create a Singleton class using PHP5 classes?
I am using PHP5 and MySql, I wondered if there was a way of
(assume php5) consider <?php $foo = 'some words'; //case 1 print these are $foo;
In our web-app we use PHP5.2.6 + PDO to connect to a SQL Server
I've taken over a mixed PHP4/PHP5 project which has been handed down from developer
We have a RedHat box with Apache2, PHP5 and MySQL 5 for much of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.