[thelist] excuses to use OOP (in PHP)

klute soundres9 at yahoo.com
Tue Jul 1 21:52:11 CDT 2003


--- Aredridel <aredridel at nbtsc.org> wrote:
> 
> Do be aware that PHP's OOP is pretty limited.  It
> has no access
> protection, it's not dynamic, it copies all objects
> instead of using
> references.  All this is fixed in 5.0, but that's
> beta.
>

Just for the sake of completeness:
a) "It has no access protection" - there is a naming
convention to be used for encapsulation in PHP.
http://www.linuxdocs.org/HOWTOs/PHP-HOWTO-7.html . If
you follow this standard, you will understand your own
code better and once PHP5 is here, your code will be
as it should be.

b) "it's not dynamic" - you mean there are no
interfaces? true

c) "it copies all objects instead of using references"
- not true, PHP4 supports references, see
http://us2.php.net/references
 
>
> Even then, PHP has a very static object model that's
> not much more than
> syntactic sugar on top of a procedural language. 
> It's just now possible
> to have accessor methods that are even vaguely
> useful, and the
> pass-by-copy is still a big problem.
>
> 
> I guess just be aware that it's not really OOP in
> PHP ;-)
> 

One of the main ideas behind OOP is making your code
modular with using classes that [logically] extend
other classes (inheritance). PHP4 supports this. If
you keep doing things procedural way, you will end up
concentrating on  non-significant details of your code
and end up with duplicate code. Once you start writing
code utilizing at least major OOP concepts, you will
catch yourself concentrating on how your system should
be designed for easier refactoring, potential system
expansions. So this fact alone makes OOP *well worth*
learning.

> [As a side note, make it known that I am an OO
> programmer who uses PHP
> entirely procedurally.  I use Ruby when I want to do
> OO work.]
> 
> Ari
> 
As for me, I started using PHP after a couple of years
of Java. Lucky for me I started out with PHP4 which
introduced inheritance. Otherwise, I would probably
not take PHP seriously.

James

p.s. for a brief tutorial on what OOP is to see if you
need it, you can check out
http://homepages.unl.ac.uk/~chalkp/proj/ootutor/oopconcepts.html
or numerous other sites.


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com


More information about the thelist mailing list