On Thu, Jul 22, 2010 at 2:40 AM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

> The larger a script or class is, the more memory this uses per instance.
>

This is not quite true. When the script is loaded, it requires a fixed
amount of memory to parse it. The larger it is, the more memory it requires.
Next, the script itself is executed, running any top-level code (not in a
class or global function). If that includes any require/include statements,
those scripts are loaded (if necessary). If it creates objects, that takes
more memory.

However, the size of each instance of the class is affected only by the data
it stores--not the number or length of its methods. PHP creates a single
internal Class object to contain the methods, and this indeed takes memory
proportional to the number of methods, but this doesn't affect the
instances. Each instance stores only its instance properties such as
$this->firstName.

This correction aside, the advice here is spot on: split your classes based
on responsibilities. The reason for this has more to do with ease of
development than performance. Say you have one monster class filled with
static methods. If your application uses most of those methods for each
request, splitting it will have no performance benefit because both scripts
will end up being loaded anyway. But if you can group the methods into
logical subsystems, they will be easier to understand and work with.

Peace,
David

Reply via email to