Re: [PHP] PHP5 and the DOM model

On Thu, Apr 17, 2008 at 5:43 PM, Nick Stinemates <nick@xxxxxxxxxxxxxx>

On Thu, Apr 17, 2008 at 10:05:11AM +0200, Michael Preminger wrote:

Seems that PHP gets more and more object oriented, which is good.

I am now running a course in PHP, using PHP 5, where we are going to
use the *DOM* interface. I am trying to teach them good OO practices,
meaning that we insistently hide properties and expose them as get or
set methods.

Get/set methods are more often than not breaking encapsulation and
should be avoided (unless purposefully designing Model object or
something similar.)

egh? we had a massive argument about this last year, but if u ask me data
hiding is an integral part of encapsulation; therefore i agree w/ Michael.

Looking at the PHPs *DOM* implementation, I see that many of the
properties are exposed directly, without even offering get methods.

so, if its a big deal, write a proxy(s) which adds the encapsulation (as u
see it) u need.

Can you please provide an example of where this is happening?

heres a list of em from DomDocument,
readonly public string
readonly public DOMConfiguration
readonly public
readonly public DOMElement<>
public string $documentURI<>;
public string $encoding<>;
public bool $formatOutput<>;
readonly public
public bool $preserveWhiteSpace<>
=true ;
public bool $recover<>;
public bool $resolveExternals<>;
public bool $standalone<>;
public bool $strictErrorChecking<>
=true ;
public bool $substituteEntities<>;
public bool $validateOnParse<>
=false ;
public string $version<>;
readonly public string
public bool $xmlStandalone<>;
public string $xmlVersion<>;

1. Is there something I am misunderstanding orotherwise missing? (I
havenot used *DOM* in PHP before).

have you looked at SimpleXMLElement / SimpleXMLIterator ?? i find it to be
one of those 80% / 20% relationships where simplexml takes care of the needs
most of the time (and saves your poor brain from smoking).

2.This poses a pedagogical problem for me as a teacher. How do I
explain this contradiction to my students?

the world doest operate 'by-the-book' thats life. i was a teacher once
(just for a semester) but i was teaching oop. at the end of the day who
knows why they did it that way. perhaps their views are different than
yours or the book from which your teaching. explain to them that there are
options, such as building a proxy, but there will be consequences in terms
of performance and increased complexity.