I have a some experience in OOP, primarily with Java and JavaScript, and a
little with PHP4. I have just checked some texts about upcoming PHP5
features, and particularly the OOP ones, and there is something that puzzles
me.
Although OOP is a great way to program and especially to keep your code and
design neat and easy to update, I still see PHP as a procedure-oriented
language, and don't see what is to be gained by introducing the plethora of
OOP features. I mean, PHP is (primarily) used for server-client HTTP-based
applications, where on each HTTP request the script is evaluated, parsed and
performed again. Even if we put all our code into a single PHP file (which
is a common practice) and the code is cached to speed things up, we still
have a blank slate each time the file is called, and we have to resend all
the values.
In my opinion, one of the points of OOD is to have a bunch of objects which,
once constructed, exist in some sort of "virtual reality" and interact with
each other, sending each other messages and changing each other's states.
Web's architecture is not the perfect environment for this approach, but it
can be done the way it is with JSP, where we can have persistent JavaBeans,
which interact with HTTP requests as if they were other objects.
I might have misunderstood the concepts behing PHP5 and Zend Engine 2, but I
don't see buch point in OOP approach if an object exists only while a script
is being executed. I would like to hear any clarifications, as well as other
people's others opinions on that subject.
Best regards,
Berislav 8 2183
On 13-Jan-2004, "Berislav Lopac" <be************@dimedia.hr> wrote: I have a some experience in OOP, primarily with Java and JavaScript, and a little with PHP4. I have just checked some texts about upcoming PHP5 features, and particularly the OOP ones, and there is something that puzzles me.
Although OOP is a great way to program and especially to keep your code and design neat and easy to update, I still see PHP as a procedure-oriented language, and don't see what is to be gained by introducing the plethora of OOP features. I mean, PHP is (primarily) used for server-client HTTP-based applications, where on each HTTP request the script is evaluated, parsed and performed again. Even if we put all our code into a single PHP file (which is a common practice) and the code is cached to speed things up, we still have a blank slate each time the file is called, and we have to resend all the values.
In my opinion, one of the points of OOD is to have a bunch of objects which, once constructed, exist in some sort of "virtual reality" and interact with each other, sending each other messages and changing each other's states. Web's architecture is not the perfect environment for this approach, but it can be done the way it is with JSP, where we can have persistent JavaBeans, which interact with HTTP requests as if they were other objects.
I might have misunderstood the concepts behing PHP5 and Zend Engine 2, but I don't see buch point in OOP approach if an object exists only while a script is being executed. I would like to hear any clarifications, as well as other people's others opinions on that subject.
PHP sessions allow for objects to persist between 'pages'. They can also be
serialized to a database or file which even allows for object sharing
between 'clients'. I guess I don't see the problem.
--
Tom Thackrey www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Berislav Lopac wrote: I might have misunderstood the concepts behing PHP5 and Zend Engine 2, but I don't see buch point in OOP approach if an object exists only while a script is being executed. I would like to hear any clarifications, as well as other people's others opinions on that subject.
The point of OOP is not to have application level objects that stay
around between requests. That is just a useful additional feature of
some languages like Java when used in a web environment.
If you're writing programs that go beyond a simple one-page-one-response
level, you want to structure your programs in a flexible, extensible,
reusable manner, maybe use design patterns and refactoring, and OOP
enables you to do that.
Just my 2c
Jochen
I totally agree with you - for simple applications OOP is of little use.
However it comes into play as things get more complex.
For larger applications I tend to write a class library encompassing
most of the application structure, abstracting the database layer and
prsenting a simple set of objects to my procedural pages. This is of use
even if the objects aren't persistent.
When you then add session support to that your objects are persistent
from page to page. Then OOP really comes into its own.
Kevin Thorpe wrote: I totally agree with you - for simple applications OOP is of little use.
However it comes into play as things get more complex.
For larger applications I tend to write a class library encompassing most of the application structure, abstracting the database layer and prsenting a simple set of objects to my procedural pages. This is of use even if the objects aren't persistent.
When you then add session support to that your objects are persistent from page to page. Then OOP really comes into its own.
However, it is still impossible to create application-wide objects like it
is possible with JavaBeans -- a new object is always re-created for each new
session. It is possible to save any changes in its state to database or a
config file, but then the application should check it on every request,
which makes it meaningless.
Berislav
Berislav Lopac wrote: Kevin Thorpe wrote:
I totally agree with you - for simple applications OOP is of little use.
However it comes into play as things get more complex.
For larger applications I tend to write a class library encompassing most of the application structure, abstracting the database layer and prsenting a simple set of objects to my procedural pages. This is of use even if the objects aren't persistent.
When you then add session support to that your objects are persistent from page to page. Then OOP really comes into its own.
However, it is still impossible to create application-wide objects like it is possible with JavaBeans -- a new object is always re-created for each new session. It is possible to save any changes in its state to database or a config file, but then the application should check it on every request, which makes it meaningless.
Sessions do that internally for you. The default session handler
serializes(sic) any variables and objects in $_SESSION to a disk file
and restores them for your next page. It's completely possible to
replace the handler with one that keeps the objects live (usually by
having a session server to hold the actual objects). In practice there's
no difference to your application.
Kevin Thorpe wrote: Berislav Lopac wrote: However, it is still impossible to create application-wide objects like it is possible with JavaBeans -- a new object is always re-created for each new session. It is possible to save any changes in its state to database or a config file, but then the application should check it on every request, which makes it meaningless.
Sessions do that internally for you. The default session handler serializes(sic) any variables and objects in $_SESSION to a disk file and restores them for your next page. It's completely possible to replace the handler with one that keeps the objects live (usually by having a session server to hold the actual objects). In practice there's no difference to your application.
I think I didn't explain clearly enough what I head in mind. By
application-wide objects I mean those that are active as long as the
application (basically, the Web server) is up, and each visitor interacts
with the exact same object (through references). That is virtually
impossible in PHP4, where you copy objects instead of references on
returning etc., but PHP5 is supposed to have a Java-like ability to return
references to objects by default.
This makes possible that system-wide preferences are always reachable as
objects, and as soon as an object's state is changed, all the following
requests will recognize the new state, without relying on databases or
serialization.
Berislav
With total disregard for any kind of safety measures "Berislav
Lopac" <be************@dimedia.hr> leapt forth and uttered: However, it is still impossible to create application-wide objects like it is possible with JavaBeans
Thats because PHP is not Java.
Just because PHP can't do everything Java is capable of does not
render the fundamental concepts of object-orientation useless.
--
There is no signature.....
I am the lead designer on a project that consists of roughly 5000
source files, and a 60,000,000 row database (~ 6 gb) with about 200
tables.
We have VERY successfully used the limited oop features of php4 to
abstract and centralize portions of our code, for instance:
CMySQLConnection is a class that connects to mysql and provides
methods such as $oConnection->
GetRow()
GetValue()
GetObject()
GetArray()
GetObjectArray()
GetResultObject()
etc...
We have a CSession class that is extended into CAdminSession and
CMemberSession with methods such as $oSession->
CheckSession()
RequireSession()
GetUserID()
GoHome()
GetVar()
SetVar()
SaveVars() (will implement this in a destructor in php5)
Also we use classes such as CContact CCustomer CMember CAdmin
CAuthorizeNetInterface CEmailSystem CBillingSystem, CAdminPage,
CMemberPage, etc...
All in all, OOP has allowed us a great way to program in a complex
enviroment and reuse our code. The session handling is a good
example. We have a CSession base class, and when we need a session
setup, we extend another class from CSession and override 2 methods
(the constructor and ValidateUser).
It may not emulate all of the features of Java, but then again if you
wanted that, prehaps you should just use Java. OOP is a great way to
organize and code large projects.
Sincerely,
Jason Garber
Chief Technology Officer
IonZoft, Inc.
"Berislav Lopac" <be************@dimedia.hr> wrote in message news:<bu**********@ls219.htnet.hr>... Kevin Thorpe wrote: Berislav Lopac wrote: However, it is still impossible to create application-wide objects like it is possible with JavaBeans -- a new object is always re-created for each new session. It is possible to save any changes in its state to database or a config file, but then the application should check it on every request, which makes it meaningless.
Sessions do that internally for you. The default session handler serializes(sic) any variables and objects in $_SESSION to a disk file and restores them for your next page. It's completely possible to replace the handler with one that keeps the objects live (usually by having a session server to hold the actual objects). In practice there's no difference to your application.
I think I didn't explain clearly enough what I head in mind. By application-wide objects I mean those that are active as long as the application (basically, the Web server) is up, and each visitor interacts with the exact same object (through references). That is virtually impossible in PHP4, where you copy objects instead of references on returning etc., but PHP5 is supposed to have a Java-like ability to return references to objects by default.
This makes possible that system-wide preferences are always reachable as objects, and as soon as an object's state is changed, all the following requests will recognize the new state, without relying on databases or serialization.
Berislav This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cody |
last post by:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.
i heard people say C++ is slower than C but i can't...
|
by: pout |
last post by:
What are the purposes of fixed-point? When should it be used?
I read:
#define Int2Fixed(x) (((long)(short)x) << 16)
and the fixed-point in 16.16 format. Does the 16 in the MACRO refer to...
|
by: Skybuck Flying |
last post by:
Hi,
I needed a method to determine if a point was on a line segment in 2D. So I
googled for some help and so far I have evaluated two methods.
The first method was only a formula, the second...
|
by: Action |
last post by:
Point is a struct
but I can do both
Point a;
Write(a.X);
Write(a.Y);
and
Point a = new Point(1,1);
Write(a.X);
|
by: Tamir Khason |
last post by:
Somebody knows how to convert Bounds to Point ???
Thnx
|
by: Peter Proost |
last post by:
Hi group,
I've got this bit of code (see below) which draws a basketball field in a
picturebox (width:198, height:368)
but now I was wondering what would be the easiest way to check inside the...
|
by: DanielJohnson |
last post by:
I wrote a simply program with a 3 D coordinate called point. I am
adding two points, taking their distance etc. gcc compiler is not
identifying the struct. Here is the code. I get bunch of errors....
|
by: rembremading |
last post by:
Hi all!
The following piece of code has (for me) completely unexpected behaviour.
(I compile it with gcc-Version 4.0.3)
Something goes wrong with the integer to float conversion.
Maybe somebody...
|
by: Linda Liu[MSFT] |
last post by:
Hi George,
Thank you for posting!
This is a quick note to let you know that I am doing research on this issue
and will get back to you ASAP.
I appreciate your patience!
Sincerely,
|
by: raylopez99 |
last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to
modify a Point, which I had made have a property. It's pointless to
do this (initially it will compile, but you'll run into...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |