Re: arrangement of class functions

From: Date: Thu, 24 Apr 2003 03:27:27 +0000
Subject: Re: arrangement of class functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145113@lists.php.net to get a copy of this message
it doesn't really matter what order you put your functions in, but i personally like to put em in a sort of hierarchical order. i write classes a lot, some very extensive ones. each of my projects generally has a set of auxiliary classes, like for handling strings/numbers/etc. and then i like to write another class which handles whatever project specific tasks i need (like class.siteFunctions.inc or something). i set the class up like this: class myClass { # This function does something to a variable function numberOne($somevar) { return something; } #--------------------------------------------------------------------------- ---------------------------# # This function formats a variable and displays it function numberTwo($somevar) { $someVar = $this->numberOne($someVar); return $someVar; } } this example is pretty basic, but the idea is that each function is seperated clearly and commented at the beginning. notice also the order i used. function number two uses function number one, so more often than not it makes sense to put function one first. anyway, i hope that helps. -jake "Prince" <friendly@kaltelnet.net> wrote in message news:009501c30a0e$0d5378e0$2904a40c@andy... > hi... > was just wondering if there was any particular way functions should be > arranged in a class or doesnt it really matter? i came up with some ideas > but dont really know what way is any better than the other... i could do > alphebetic a-z or z-a, by type of function, by what the function does and > all sorts of things i can come up with... just what one is the better one of > them... > > > >

« previous php.general (#145113) next »