By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,669 Members | 3,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,669 IT Pros & Developers. It's quick & easy.

PHP 5 & OO

P: n/a
Hello all,

Over the last couple of month, since the release of PHP 5 I have been
involved in a number of heated discussions which sometimes reduced them
selves to blatant name calling and an occasional deodorant throw, which
if I mad add, was precisily aimed at my head. I am talking about my
wife, who if I failed to mention is not only a good shot *ouch*, but has
also recently delved into the realm of Object Oriented - PHP Programming.

So what is this topic that turned a regular suburban wife into a
tigress?! Well... I shall start from the start, in fact I'll make the
question fairly short, as my fingers are getting tired from all that
creative typing that I've done over the last one and a half paragraphs.
PHP... Objects... Orientation... *the non-sexual kind*

Sure most of us know these concepts from Java or C++ or ASP.NET. OO
refers to a approach to programming, I'm not going to blabber on about
OO as thats an entire can of worms in it self, but the general concept
is that you logicly group data into these containers known as objects
and then throw them into memory for your logic to play around with. But
this works fairly different in PHP, as HTTP is a *stateless* protocol.
Which means PHP doesn't really remember it-self from one execution from
the next.

Moving even deeper in...

The only mechanic in PHP to transcend this problem at the moment is with
the use of Sessions, which are just regular files. I could only imagine
the performance hit involved in finding out if another user on the
system had a certain object loaded into a SESSION... and what if this
PHP application had thousands of concurrent users? Would you have to
iterate though all the *session* files to find the one with that object
open? Yes, you would. So essentially we would be doing exactly the same
thing. Reloading the objects. Which is just silly as that is what we are
trying to avoid.

Alternatively there are a PHP library know as the *SHM* which provide a
channel for several PHP processes to be able to communicate. I still
haven't used this and to be honest after dozens of projects I still
would not commit my or my sub ordinate's time into development of any
code based on this library.

As some of you may know SHM is a highly experimental set of functions
for PHP, which allow you several C process to be able to talk to one
UNIX shared memory segment. But anyway...

So what is the point of OO in PHP?
To make the code appear neater?
To allow greater maintainability?
Why are people talking about PHP6 & Name spacing? :)

Oh yeah, and my question:
How are 2 users able to share a run-time object in memory?
Is it even possible?
How do you get around the problem? EZPDO? DB::DataObject?

If any in this user group is still awake by the end of my post? And is
able to answer any of these questions? Or simply wants to say: "Hey man
your post sucks!".

Please feel free to do so.

Please...

Pretty Please.
Aug 24 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
Ramon wrote:
Hello all,

Over the last couple of month, since the release of PHP 5 I have been
involved in a number of heated discussions which sometimes reduced them
selves to blatant name calling and an occasional deodorant throw, which
if I mad add, was precisily aimed at my head.
Sounds like you deserved it Ramon ;)

The only mechanic in PHP to transcend this problem at the moment is with
the use of Sessions,
No. An object can be treated as a piece of data. Since you're using PHP5,
you don't even have to worry about ensuring the class is loaded before
de-serializing the object. The object can be stored in a file, in a
database, in a form field....just about anywhere (except maybe a cookie -
'cos of the size).
which are just regular files.
No. The default session handler uses files. You can use any store PHP can
interface with - DBs, shared memory, files, cluster shared memory....
I could only imagine
the performance hit involved in finding out if another user on the
system had a certain object loaded into a SESSION...
Very little in the grand scheme of things. Why not measure it?
and what if this
PHP application had thousands of concurrent users? Would you have to
iterate though all the *session* files to find the one with that object
open? Yes, you would.
Whoa - you mean you have a class which can onlybe instantiated by a single
user? And you want to access other peoples sessions from within your code?
Where's my deoderant can - no, make that a brick.
So what is the point of OO in PHP?
To make the code appear neater? No, although, in principle anything done with OO can be acheived using
procedural or even functional code. The former just makes it much simpler
(particularly if interfaces are inportant).
To allow greater maintainability? See prev answer.
Why are people talking about PHP6 & Name spacing? :)
Never written a large PHP application Ramon?
Oh yeah, and my question:
How are 2 users able to share a run-time object in memory?
Is it even possible?
How do you get around the problem? EZPDO? DB::DataObject?


This is damn tricky to do with Java/C++ etc. That's why there's Corba, COM,
DCOP, ORBit, D-BUS....
One wonders what problem causes you to think this is the solution.
Hey man your post sucks!

C.

Aug 24 '05 #2

P: n/a
Ramon wrote:
Oh yeah, and my question:
How are 2 users able to share a run-time object in memory?
Is it even possible?
How do you get around the problem? EZPDO? DB::DataObject?


Interesting post, thanks.
I've been having related thoughts on Windows systems...
http://groups-beta.google.com/group/...99969e892cab48

Csaba Gabor from Vienna

Aug 24 '05 #3

P: n/a
Following on from Ramon's message. . .

You have decided on the basis of false assumptions and poor research and
slim grasp of realities that OO is cosmetic in the PHP context. You are
wrong. Please see the many similar threads on the subject - preferably
in another ng.
Hello all,

Over the last couple of month, since the release of PHP 5 I have been
involved in a number of heated discussions which sometimes reduced them
selves to blatant name calling and an occasional deodorant throw, which
if I mad add, was precisily aimed at my head. I am talking about my
wife, who if I failed to mention is not only a good shot *ouch*, but has
also recently delved into the realm of Object Oriented - PHP Programming.

[blah blah blah]

There is a new concept which you may not have come across called a
database which is ideally suited to persistence. If you want to do Java
things with PHP then you should research the subject a bit more.

--
PETER FOX Not the same since the pancake business flopped
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Aug 24 '05 #4

P: n/a
Ramon wrote:
How are 2 users able to share a run-time object in memory?


A very brief answer: They are not, and they not need to be. As you rightly
said, HTTP is stateless, and PHP follows this concept.

Also keep one more thing in mind: PHP is some kind of a pushmi-pullyu
monster: on one site it's a Web development framework, but at the same time
it is also its own scripting language. So you can't do most things you can
do with common purpose languages, as PHP is *not* a common purpose language.

Berislav
Aug 24 '05 #5

P: n/a
and what if this
PHP application had thousands of concurrent users? Would you have to
iterate though all the *session* files to find the one with that object
open? Yes, you would.


There are instances where this is actually used quite frequently in web
services - such as a wrapper class for db execution. Limiting the
number of concurrent uses of a db connection object by initiating X
number fo connection objects, then leasing them out to users or objects
that require them.

In java/jsp/j2ee these would be objects with application scope (alive
as long as the applicaiton is running, instead of sesssion based or
page based).

I can't say exactly why you need to do this, but I've never seen a
similar thing in PHP (not syaing it doesn't exist but I am not an
authority on cutting edge PHP, or even PHP OO tbh).

Just my two cents.

Rick
www.e-connected.com

Aug 24 '05 #6

P: n/a
thehuby wrote:
In java/jsp/j2ee these would be objects with application scope (alive
as long as the applicaiton is running, instead of sesssion based or
page based).

I can't say exactly why you need to do this, but I've never seen a
similar thing in PHP (not syaing it doesn't exist but I am not an
authority on cutting edge PHP, or even PHP OO tbh).


No, PHP doesn't have application-level scope. I was (and still am) planning
to write a module for PHP5 which would utilize SQLite for maintaining
application-level persistance, but didn't find the time yet. :(

Berislav
Aug 24 '05 #7

P: n/a
thehuby wrote:
and what if this
PHP application had thousands of concurrent users? Would you have to
iterate though all the *session* files to find the one with that object
open? Yes, you would.

There are instances where this is actually used quite frequently in web
services - such as a wrapper class for db execution. Limiting the
number of concurrent uses of a db connection object by initiating X
number fo connection objects, then leasing them out to users or objects
that require them.

In java/jsp/j2ee these would be objects with application scope (alive
as long as the applicaiton is running, instead of sesssion based or
page based).

I can't say exactly why you need to do this, but I've never seen a
similar thing in PHP (not syaing it doesn't exist but I am not an
authority on cutting edge PHP, or even PHP OO tbh).

Just my two cents.

Rick
www.e-connected.com


There's a good reason why you haven't seen it in PHP. It can't be done at the
page level - at least not easily. For instance - what would you do if there are
no pages being processed? There would be no objects to manage the connection pool.

A Java application could roughly be equated to a PHP page - the code starts when
the page execution begins and is all cleaned up when the page execution ends.
And once the Java app ends, everything there is cleaned up, also.

What you would probably need would be an Apache extension to manage the pool
then code to that extension.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 24 '05 #8

P: n/a
Berislav Lopac wrote:
Ramon wrote:
How are 2 users able to share a run-time object in memory?


A very brief answer: They are not, and they not need to be. As you rightly
said, HTTP is stateless, and PHP follows this concept.

Also keep one more thing in mind: PHP is some kind of a pushmi-pullyu
monster: on one site it's a Web development framework, but at the same
time it is also its own scripting language. So you can't do most things
you can do with common purpose languages, as PHP is *not* a common purpose
language.

Berislav


But it plays one on TV.

But seriously, what does PHP lack to make it common purpose? It can
read/write streams, talk to databases, recurse loops, perform various list
operations, and it runs from the command line, what is missing?

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Aug 24 '05 #9

P: n/a
On Wed, 24 Aug 2005 16:58:04 +1000, Ramon wrote:
So what is the point of OO in PHP?
To make the code appear neater?
To allow greater maintainability?
The point of OO is the same in PHP5 as is everywhere else: it allows
encapsulation and code reuse. It also allows much simpler error checking
using try { } catch {} blocks. Libraries like ADOdb are written using
OO methodology and are much easier to use then the pure procedural
equivalents. It speeds up coding and allows code reuse, among other things.
Why are people talking about PHP6 & Name spacing? :)


People are talking about Brittney Spears and Desperate Housewives, too.
Oprah Winfrey and Jerry Springer made fortunes on idiotic things that
people are talking about. This is wrong newsgroup for a question like this.

--
http://www.mgogala.com

Aug 24 '05 #10

P: n/a
On Wed, 24 Aug 2005 08:41:54 -0400, Kenneth Downs wrote:
But seriously, what does PHP lack to make it common purpose? It can
read/write streams, talk to databases, recurse loops, perform various list
operations, and it runs from the command line, what is missing?


My answer would be "formats" or "report writer". They are the reason why
I am using Perl for CLI stuff. Also, Perl supports array interface and
bulk loads while PHP does not. That makes Perl scripts much, much faster
when you need to load a file into database.

--
http://www.mgogala.com

Aug 24 '05 #11

P: n/a
On Wed, 24 Aug 2005 14:04:50 +0200, Berislav Lopac wrote:
No, PHP doesn't have application-level scope. I was (and still am) planning
to write a module for PHP5 which would utilize SQLite for maintaining
application-level persistance, but didn't find the time yet. :(


I usually link my PHP with --with-oci8 --without-sqlite --disable-mysql
arguments. That's how I like it.

What would be the point of that application level persistence in PHP5?
Any app server (Weblogic, WebSphere, iPlanet, iAS) has application
persistence. The purpose of PHP5 is not to replace Java or .Not, but to
complement them.

--
http://www.mgogala.com

Aug 24 '05 #12

P: n/a
Mladen Gogala wrote:
On Wed, 24 Aug 2005 08:41:54 -0400, Kenneth Downs wrote:
But seriously, what does PHP lack to make it common purpose? It can
read/write streams, talk to databases, recurse loops, perform various
list operations, and it runs from the command line, what is missing?


My answer would be "formats" or "report writer". They are the reason why
I am using Perl for CLI stuff. Also, Perl supports array interface and
bulk loads while PHP does not. That makes Perl scripts much, much faster
when you need to load a file into database.


C does not have those either. Rather than the term "common purpose"
programming language, perhaps you mean something more like 4GL or
higher-level language?

My thinking is that a common purpose programming language allows me to make
anything for myself, like a formatting system.

As for bulk loads, aren't those a feature of the db server? If the db
server supports it, then PHP ought to be able to feed it. Or do I
misunderstand?

And on a lighter note, speaking of formats, I will probably have to write a
slew of commands that I miss from foxpro, like

fox_format($mynumber,"999,999.99")

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Aug 24 '05 #13

P: n/a
On Wed, 24 Aug 2005 16:35:10 -0400, Kenneth Downs wrote:

C does not have those either. Rather than the term "common purpose"
programming language, perhaps you mean something more like 4GL or
higher-level language?
C is, essentially, portable macro-assembly language. It's main purpose is
to write system programs, not to be used as a scripting language, although
I have to admit that I used it like a scripting language in combination
with flex.

My thinking is that a common purpose programming language allows me to make
anything for myself, like a formatting system.
Depends on what do you mean by "common purpose". Every programming
language is a common purpose programming language, but scripting
language for ad hoc tasks must have certain high level constructs
like regular expressions and formats available. Things like

$dir .= "/" unless $dir =~ /\/$/;

or

$dir ||= "/tmp"; (This is actually a neat and dirty trick to say
if (!defined($dir)) { $dir = "/tmp"; } )

are extremely convenient, relatively short and easy to write. That is
why Perl is so extremely popular (the above line is from Perl script,
in case anybody wondered)


As for bulk loads, aren't those a feature of the db server? If the db
server supports it, then PHP ought to be able to feed it. Or do I
misunderstand?


Unfortunately, it's not that simple. Oracle supports bulk loads but
one cannot be used from PHP. PHP is primarily web scripting language
and it reflects on its structure. Large bulk loads are almost never a
part of web applications. The same logic applies to the formatting.
Writing large, multi-paged ASCII text reports and sending them to
printer is usually not a part of web-based application. Displaying
things in tables, by using PEAR HTML_Table or something similar is.
It's much easier to create a HTML table in PHP then in Perl. That's
what PHP is intended for.
--
http://www.mgogala.com

Aug 24 '05 #14

P: n/a
Colin McKinnon wrote:
Ramon wrote:

Hello all,

Over the last couple of month, since the release of PHP 5 I have been
involved in a number of heated discussions which sometimes reduced them
selves to blatant name calling and an occasional deodorant throw, which
if I mad add, was precisily aimed at my head.

Sounds like you deserved it Ramon ;)


Yes, probably did.

The only mechanic in PHP to transcend this problem at the moment is with
the use of Sessions,

No. An object can be treated as a piece of data. Since you're using PHP5,
you don't even have to worry about ensuring the class is loaded before
de-serializing the object. The object can be stored in a file, in a
database, in a form field....just about anywhere (except maybe a cookie -
'cos of the size).


Thats exactly write, but what you are saying is that every time I want
to interact with an object I have to read io or right? not memory. And
say my project has good 70 objects, some of them very large, and a 1000
users concurently browsing. So in theory every time a user loads a page
I have to load some or all of those? Times the number of users... and
you are saying there isnt a performance hit involved? You must be kidding.
and what if this
PHP application had thousands of concurrent users? Would you have to
iterate though all the *session* files to find the one with that object
open? Yes, you would.

Whoa - you mean you have a class which can onlybe instantiated by a single
user? And you want to access other peoples sessions from within your code?
Where's my deoderant can - no, make that a brick.

No, I want if you took the time to read my post with abit less gusto,
you would understand that my question is: "How can I have two or more
users using the same object at the same time?"
Never written a large PHP application Ramon?

Should have thought that even a humarous approach to a reasonable
question would be met with hostility and anger. It's a news group after
all. And yes, I have written alot of large scale applications.

Hey man your post sucks!


That I know.
Aug 25 '05 #15

P: n/a
Peter Fox wrote:
Following on from Ramon's message. . .

You have decided on the basis of false assumptions and poor research and
slim grasp of realities that OO is cosmetic in the PHP context. You are
wrong. Please see the many similar threads on the subject - preferably
in another ng.
Hello all,

Over the last couple of month, since the release of PHP 5 I have been
involved in a number of heated discussions which sometimes reduced them
selves to blatant name calling and an occasional deodorant throw, which
if I mad add, was precisily aimed at my head. I am talking about my
wife, who if I failed to mention is not only a good shot *ouch*, but has
also recently delved into the realm of Object Oriented - PHP Programming.


[blah blah blah]

There is a new concept which you may not have come across called a
database which is ideally suited to persistence. If you want to do Java
things with PHP then you should research the subject a bit more.


Thanks for the kind words, but I have researched the subject, quite
extensively. And I turned to this news group for advice, so get of your
high horse. My post was not aimed to belittle PHP in any way or form. As
for my *grasp* I'm sure it is sufficient for this discussion. But hey,
this isn't a competition.

So lets review, what did you accomplish in your post?

Did you answer any of my questions? - No.
Did you provide any advice or hints in your post? - No.

Now, speaking of my wife. She always said: "If you can't say anything
good, don't say anything at all!". Now gentlemen, lets follow that
advice shall we. If my post has offended someone (although I can't
imagine how or why that would happen)...

Please accept my apology.

Have a good day.

D.

So please, enlighten me how am I able
Aug 25 '05 #16

P: n/a
Mladen Gogala wrote:
On Wed, 24 Aug 2005 16:35:10 -0400, Kenneth Downs wrote:

C does not have those either. Rather than the term "common purpose"
programming language, perhaps you mean something more like 4GL or
higher-level language?


C is, essentially, portable macro-assembly language. It's main purpose is
to write system programs, not to be used as a scripting language, although
I have to admit that I used it like a scripting language in combination
with flex.

My thinking is that a common purpose programming language allows me to
make anything for myself, like a formatting system.


Depends on what do you mean by "common purpose". Every programming
language is a common purpose programming language, but scripting
language for ad hoc tasks must have certain high level constructs
like regular expressions and formats available. Things like

$dir .= "/" unless $dir =~ /\/$/;

or

$dir ||= "/tmp"; (This is actually a neat and dirty trick to say
if (!defined($dir)) { $dir = "/tmp"; } )

are extremely convenient, relatively short and easy to write. That is
why Perl is so extremely popular (the above line is from Perl script,
in case anybody wondered)


As for bulk loads, aren't those a feature of the db server? If the db
server supports it, then PHP ought to be able to feed it. Or do I
misunderstand?


Unfortunately, it's not that simple. Oracle supports bulk loads but
one cannot be used from PHP. PHP is primarily web scripting language
and it reflects on its structure. Large bulk loads are almost never a
part of web applications. The same logic applies to the formatting.
Writing large, multi-paged ASCII text reports and sending them to
printer is usually not a part of web-based application. Displaying
things in tables, by using PEAR HTML_Table or something similar is.
It's much easier to create a HTML table in PHP then in Perl. That's
what PHP is intended for.


I'm impressed with your knowledge of other systems, but your conclusions are
not supported by the facts you present. You might better say, "large bulk
loads are almost never a part of the web application *Mladen* *has*
*seen*", because they are out there (I wrote one the other day). Making
large multi-paged reports is certainly more and more a part of web apps.
We do strictly web database apps and so all of our reports come out of the
browser.

Cheers and I hope we discuss other interesting topics again soon.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Aug 25 '05 #17

P: n/a
Session variable is not the only one that you can put objects in. Yeah,
objects specific to the session should be kept in it, but you never
need to reach it from another session, as it is the other session's
object. But if you want some object that is used application wide, you
can do serialization on the database or some flat file, using it over
all users as required. But that would not be a solution for memory
usage I guess, as every user has to have an instance of the object.

If that is needed, smth like a web service or soap can be the solution.
One instance of the service runs in the server and the code that needs
to use the service connects and queries for data.

The thing for writing oop in any language is not just that. Not being
able to use the same object over multiple users should not be the
motive that drives you towards procedural programming in any language.
That is a problem to be overcomed, but that does not prove that oop is
not efficient, as oop promises a lot more than this.

Aug 25 '05 #18

P: n/a
Mladen Gogala wrote:
What would be the point of that application level persistence in PHP5?
Any app server (Weblogic, WebSphere, iPlanet, iAS) has application
persistence.
Except PHP. That's the point of adding app-level persistence to PHP5. That
might not be useful everywhere, but ocassionaly it might.
The purpose of PHP5 is not to replace Java or .Not, but
to complement them.


Those are three different things.

- PHP is a Web application server with its own scripting language (also
called PHP).
- Java is a general purpose language with lots of libraries, frameworks and
applications for various purposes, including Web application servers.
- .NET is a general purpose development platform, with lots of libraries and
frameworks for various purposes, which supports a number of different
programming languages.

So they definitely can't replace each other. They can each be used on its
own for most purposes, or can be glued together if needs be.

Berislav
Aug 25 '05 #19

P: n/a
On Thu, 25 Aug 2005 10:30:30 +1000, Ramon <dr*****@gmail.com> wrote:
Thats exactly write, but what you are saying is that every time I want
to interact with an object I have to read io or right?
Fortunately nobody in their right mind develops a PHP application that
way. Your best bet is to treat PHP as stateless just like HTTP.
And
say my project has good 70 objects, some of them very large, and a 1000
users concurently browsing. So in theory every time a user loads a page
I have to load some or all of those? Times the number of users... and
you are saying there isnt a performance hit involved? You must be kidding.


Of course, if you have 70 shared objects and a 1000 years you're going
to have serious performance issues with regards to locking
irregardless of platform.
Aug 25 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.