[UPHPU] Article 2
bigdog at venticon.com
Mon Jun 20 17:05:03 MDT 2005
> It seems to me that there is a "LOT" of structure needed when you begin an
> OOP project. And that you really need to have your program outline
> pretty detailed, thats understandable. But what I don't really get is
> when folks who like OOP, say that its reusable. But then so is a
yes it is true that many oop apps need to be thought out first and for
most with oop design in the initial design phase of your software dev cycle.
> When I first heard about OOP I was learning Pascal and C. And in a "real"
> program, (for lack of a better term), such as would be written in C++ or
> Java, or C, when you load a program into memory, your Objects get loaded
> and then become reusable without having to realocate memory space. That
> was the definition I was given when it was "coming of age".
> But with PHP, everytime your script halts all of that gets dumped. Its
> not "reusable" in the same sense because your script halts and whatever
> PHP code that was in memory is gone. So that also means that everytime
> you load a script, all of that extra coding used to build your Object has
> to be reloaded for each page load. This may or may not be noticable to
> the human eye in speed, but it surely must have a bigger load than simply
> including my "functions.php" file on each page load.
true the persistent object memory alloction does not exist in php
without using some type of shared memory (with does not work on windows)
or you will have to serialize objects for actual object instance reuse.
there are other issues with code reusability that have not been talked
about yet. (check comments on first article on the website for some
insight into this.)
one thing i want to mention is that php is not an object oriented
language in the full aspect. it lacks many features of oop like method
(function) overloading. with that said, the issue of reusable code is
that you can reuse the class definition just like a function definition.
in the terms of oop reusable code means that you create object
(instantiate) objects from a class definition and reuse that object over
and over. For example, you will see man sites that instantiate a db
object and use that to connect to the backend. with an object you can
then encapsulate properties and methods to that object that let you work
on that data. procedural programming will not allow you to do this type
for example, lets say that i have an db object that contains various
methods that sort, arrange and modify the data retrieved from a
database. This can all be encapsulated inside the object and i dont have
to move data from method to method and have return values or pass by
then you can start instanstiating objects that represent real world
objects. like for example a user. then you can subclass that object to
be various types of users. so then we can create a customer user. with a
customer user we can encapsulate all their customer data, address info,
purchasing habits, credit information all in a single object. this then
would reduce the need to move all this data between functions to modify
the data. and each object would have the ability to encapsulate the data
as you define in the objects.
> Can anyone, does anyone, want to shead some light on this for me? I
> really don't understand the value of OOP in PHP. Its laborous to write
> and its an extra load on the server when it loads, and it gets dumped
> after the page halts, so whats the value? Now if PHP had a "daemon" that
> kept all Objects in memory and you could just reference those objects when
> inside a PHP script, that would seem useful and fill the OOP definition.
More information about the UPHPU