Re: [Phpslash-devel] OOP & php programming style
Brought to you by:
joestewart,
nhruby
From: nathan r. h. <na...@ds...> - 2002-03-15 18:04:31
|
In a pure OO world we would want accessor and modifier methods so that we never ever ever touch an objects properties. Accessor methods make it easier to do error checking on input data and make sure that the varaible data is in the correct form for when the object uses it. That said, php is a loosely typed langauge with a fucked up namespace (Zend2 will fix that somewhat with perl like namespaces, but as with all new php functions.. it'll take some time to be truly useful). Accessor functions also take time to build and there's some overhead to run, not a good thing in a compile-per-execution environment as we are. Also, what gets overlooked with accssor functions in the overhead in their implementation. Take for example class foo { var foolio = "bar"; function setFoolio($desiredValue) { if ($desiredValue = $this->foolio) { return 0; } else { $desiredValue = strToUpper($desiredValue); // blah blah blah $this->foolio = $desiredValue; return 0; } } } What would the laod be if you reset $foo->foolio 20 times per page? What happens if $setFoolio() actually starts checking type, content and starts returning all kinds of errors? Then you end up with the Mess that PEAR is in right now, where everythign you do if followed by if (pear::isError($retObj)) { //do a bunch of pear error object crap die(); } It can bog down a applciation with lots and lots of ectra calls and code overhead for pedantic checking on everything that you do. Granted, in a perfect world this is most certianly the way to do things, but in php, I think it tends to lead to very poor performance (unless you throwdown the bucks for the Zend Compiler) and generally is a bitch to maintain unless you designed this way from the start. -n ------ nathan hruby na...@ds... ------ On Fri, 15 Mar 2002, Joe Stewart wrote: > List discussion is kind of slow, so... > > With my small understanding of OOP concepts, I'm trying to relate the use > to php. > > Should we always return object variables from outside the object via a > method? > > Use: $object->getVariable('variable'); > > or is using $object->variable OK? > > In general, since php is an interpreted language I try to keep function > calls down, even if it means a little duplicated code. > > > Joe > > _______________________________________________ > Phpslash-devel mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpslash-devel > |