473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is OOP really appropriate for PHP?

Hi folks,

I have a basic question. When I do object-oriented programming
using C++ or Java, all my objects reside in RAM. I do not have
to think about storing and retrieving them, because they are
in RAM and that space has been allocated for them and
the program is continually running, so neither program nor
objects are going to disappear.

It seems to me, having never done OOP in PHP, that this
arrangement would not exist in PHP, because program+objects
only exist when a page is being constructed. In the meantime,
where are the objects? You might say, "in my MySQL database",
and that is certainly a capable storage medium, however
it takes time to get them out, and to store them back into it.

So the question is, I think, appropriate. Since PHP has
(AFAIK) no object storage other than a database, is
OOP in PHP really appropriate?

If there is some other storage medium can you tell me what it is?

If there isn't another faster storage medium than a database,
why doesn't someone create one, to improve efficiency?

Thanks.
Dec 2 '07 #1
4 1506
I have a basic question. When I do object-oriented programming
using C++ or Java, all my objects reside in RAM. I do not have
to think about storing and retrieving them, because they are
in RAM and that space has been allocated for them and
the program is continually running, so neither program nor
objects are going to disappear.
Well, web applications exist discontinuously, like as a film. But that
does not change anything in the need for object orientation.
It seems to me, having never done OOP in PHP, that this
arrangement would not exist in PHP, because program+objects
only exist when a page is being constructed. In the meantime,
where are the objects? You might say, "in my MySQL database",
and that is certainly a capable storage medium, however
it takes time to get them out, and to store them back into it.
In that meantime, the objects simply do not exist. The in-between
pictures of a film do not exist either. So your objects must be
retrieved and stored fast. But apart from that speed, the mechanisms are
exactly the same as for local applications.
So the question is, I think, appropriate. Since PHP has
(AFAIK) no object storage other than a database, is
OOP in PHP really appropriate?
It may be even more appropriate. Object orientation allows you to
optimize the database communication strategy (greedy, lazy, or something
in-between). This optimization helps you with every request, and not
only upon the startup of your application. If fact, your application is
restarted at every server request.
If there is some other storage medium can you tell me what it is?
You can store objects or object data in a session. This is the most
straightforward way to make your application seem to be running
continuously.

Best regards
Dec 2 '07 #2
On Dec 2, 2:56 pm, Viator <varioustr...@yahoo.comwrote:
Hi folks,

I have a basic question. When I do object-oriented programming
using C++ or Java, all my objects reside in RAM. I do not have
to think about storing and retrieving them, because they are
in RAM and that space has been allocated for them and
the program is continually running, so neither program nor
objects are going to disappear.

It seems to me, having never done OOP in PHP, that this
arrangement would not exist in PHP, because program+objects
only exist when a page is being constructed. In the meantime,
where are the objects? You might say, "in my MySQL database",
and that is certainly a capable storage medium, however
it takes time to get them out, and to store them back into it.
I am a bit confused here. In PHP, the objects are created and stored
in the Server's RAM as the script runs (when the webpage is
constructed), and as the script finishes execution, the objects are
wiped from the memory (which is a really quick process).
>
So the question is, I think, appropriate. Since PHP has
(AFAIK) no object storage other than a database, is
OOP in PHP really appropriate?

If there is some other storage medium can you tell me what it is?

If there isn't another faster storage medium than a database,
why doesn't someone create one, to improve efficiency?

Thanks.
--
Kailash Nadh | http://kailashnadh.name
Dec 2 '07 #3
Viator wrote:
Hi folks,

I have a basic question. When I do object-oriented programming
using C++ or Java, all my objects reside in RAM. I do not have
to think about storing and retrieving them, because they are
in RAM and that space has been allocated for them and
the program is continually running, so neither program nor
objects are going to disappear.

It seems to me, having never done OOP in PHP, that this
arrangement would not exist in PHP, because program+objects
only exist when a page is being constructed. In the meantime,
where are the objects? You might say, "in my MySQL database",
and that is certainly a capable storage medium, however
it takes time to get them out, and to store them back into it.

So the question is, I think, appropriate. Since PHP has
(AFAIK) no object storage other than a database, is
OOP in PHP really appropriate?

If there is some other storage medium can you tell me what it is?

If there isn't another faster storage medium than a database,
why doesn't someone create one, to improve efficiency?

Thanks.
Your problem is web programming requires a different design.

Web pages are transactional in nature. That is, the browser makes a
request, the page starts, processes the request and terminates (one
transaction). When the user does something to create another request,
the process repeats.

Most C/C++ programs are not like this - they start and keep going across
multiple requests.

But this does not affect OO design and usage. It is still very much
appropriate for transactional programming. You don't have to save the
objects to make them useful.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 2 '07 #4
On 2 Dec, 14:56, Viator <varioustr...@yahoo.comwrote:
Hi folks,

I have a basic question. When I do object-oriented programming
using C++ or Java, all my objects reside in RAM. I do not have
to think about storing and retrieving them, because they are
in RAM and that space has been allocated for them and
the program is continually running, so neither program nor
objects are going to disappear.
As the other correspondents have pointed out - that is the case with
PHP as long as the current thread is being executed. It is also true
of Java and C++ when invoked as a new execution thread via CGI - most
commonly for Java complex applications are implemented via containers
where a significant part of the process continues after the request
thread is completed.

You shouldn't have to think too much about storing/retrieving data
with PHP - read up on sessions. This of course does not address the
class definition part of an object - you can manually reference the
definitions within your code but its a lot simpler to adopt a
consistent approach to where you keep these and use the autoload
functionality (loading of a definition of a class instantiated in the
session is deferred).
however
it takes time to get them out, and to store them back into it.
Most Web based Java applications have a similar problem/overhead
because the session has to replicate across the nodes - IME this is
much more painful than PHP's session handling which is intrinsically
at the storage layer.

(I also have a pet peeve about ORM - I think its a bad idea)
So the question is, I think, appropriate. Since PHP has
(AFAIK) no object storage other than a database, is
OOP in PHP really appropriate?
You don't have to use a database. By default sessions are stored on
the filesystem but you can put them anywhere you can access via PHP -
a database or shared memory are obvious candidates. The filesystem can
easily be in RAM if you like.

Why do you think it's not fast enough?

C.
Dec 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pham Nguyen | last post by:
I haven't used the READ UNCOMMITTED transaction isolation level before, and I was wondering if this would be an appropriate use: I have an ID table containing ID numbers that are randomly...
761
by: Neo-LISPer | last post by:
Hey Recently, I researched using C++ for game programming and here is what I found: C++ game developers spend a lot of their time debugging corrupted memory. Few, if any, compilers offer...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
7
by: ddsvi78 | last post by:
I am a complete idiot when it comes to access. Now that said, I work for a computer security company and one of our customers came to us with an access problem. They had been running fine for a...
6
by: Réal Forté | last post by:
Hi, I have a puzzling case here: using System; namespace TestOverrides { class Class1
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
53
by: Alan Silver | last post by:
Hello, I understand the issue that tables should be used for tabular data and not for layout, but I would like some clarification as to exactly what constitutes tabular data. For example, if...
28
by: lovecreatesbeauty | last post by:
Besides printing out for example " a.out: p113.c:8: main: Assertion `0' failed. Aborted " and a switch option NDEBUG, what other benefits does assert() provide in any scope of designing,...
56
by: infidel | last post by:
Where are they-who-hate-us-for-our-whitespace? Are "they" really that stupid/petty? Are "they" really out there at all? "They" almost sound like a mythical caste of tasteless heathens that "we"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.