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 7536899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:42:05+00:00 2026-05-30T06:42:05+00:00

I have been writing in PHP for just over half a year now, and

  • 0

I have been writing in PHP for just over half a year now, and whilst I am a long way off being an expert, I can get around quite easily and turn out scripts for whatever I need. I come from an object-oriented background and this is something that PHP seems to use very little of, if at all, in its default libraries.


Most external libraries I use or create, work with an object-oriented design whereas the defaults seem to use the next example. I’ll use the file/writing reading process as an example:

$file_path = "/path/to/file.txt";
$file_handle = fopen($file_path, "w+");
$content = fread($file_handle, filesize($file_path));
fclose($file_handle);

Now to me, it would make more sense to be using a design that looks something like this:

$file_handle = new FileStream("/path/to/file.txt");
$content = $file_handle->read();
$file_handle->close();

Now I am quite sure that there will be a definite reasoning behind this, as the same idea is applied to strings, arrays, cURLs, MySQL queries etc. I would be interested to know what it is.

So, if it is better to write distinct functions taking a handle or resource as a first parameter e.g.

object_method($handle, $value);

Then why do most popular (external) PHP libraries prefer to use:

$object->method($value);

And which should I be using when writing my own libraries and applications?

  • 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-30T06:42:06+00:00Added an answer on May 30, 2026 at 6:42 am

    It’s because there weren’t objects when PHP was first written. There are a number of libraries that wrap basic PHP functionality with OO. Much like MFC wrapps the basic C Windows API with C++ classes.

    • http://jamessocol.com/projects/oocurl.php
    • http://www.shesek.info/php/generic-php-object-wrapper-for-resources

    If you use a framwork like Kohana, it provides lots of those wrappers for you like a File Wrapper
    http://kohanaframework.org/3.0/guide/api/File

    Here’s Kohana full API http://kohanaframework.org/3.0/guide/api/

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

Sidebar

Related Questions

I've been writing PHP for about six years now and have got to a
I have been writing C++ Console/CMD-line applications for about a year now and would
I have been writing a PHP class that is exactly 450 lines long and
I have been writing web applications for quite sometime in PHP with MySQL. I
I've been writing PHP web applications for some time, and have come across very
I have been writing articles on the wordpress.com blog , now I am looking
I'm relatively new to PHP and have been writing a project using what I
Alright now, I have been searching everywhere for a way to accomplish this and
I've been coding php for years, and now i have to finally make my
While I've been writing php for a long time, it was always a skill

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.