[thelist] excuses to use OOP (in PHP)

Aredridel aredridel at nbtsc.org
Tue Jul 1 22:32:21 CDT 2003

> 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.

They faked it, though in 5.0, they fixed that.

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

It's not dynamic.  You can't add methods at run time.  You can't do
terribly much more than you can with a procedural language.

> c) "it copies all objects instead of using references"
> - not true, PHP4 supports references, see
> http://us2.php.net/references

Broken horribly.  Crashes at least five versions of the interpreter
previous to 4.2 that I used.

> >
> > 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.

If you think of it as syntactic sugar, you can get the same effect
either way -- I have a whole library (Actually could compete with about
25% of PEAR) that I should release that's entirely procedural, but
totally modular complete with "inheritance" (or at least common
implementations of otherwise duplicated code.

> > [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.

I started when 3.0 came out... such a world of difference 4.0 made to
objects, but not enough, yet.

Coming from Java, that makes sense that you see the world as you do --
and I read over the changes for 5.0 and thought to myself "My god,
they've re-invented Java"

> 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.

And http://rubygarden.org for the Smalltalk type of OO, but in Ruby
(which is more sane to read by far)

I'm a strong advocate of the "Everything-is-an-object" sort of languages
for OO.  When you do that, you actually get some very different code
than in languages like PHP and Java that have primitive types.

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

More information about the thelist mailing list