Welcome Guest, Not a member yet? Register   Sign In
Can I load a library class without creating an instance of it? [SOLVED]

First post! Yay!

Ok, here is the deal: I try to save as much memory as I can in my app, and to do so, I use refferences a lot. In order to count the instances of my objects, all my library classes have these attributes and functions:

private static $instances=0;

public __construct(){
//Rest of constructor

public __destuct(){
//Rest of destructor

The following code shows me that an instance is created at load time

echo "Instances of ClassName in memory: ".ClassName::$instances;

//Outputs: Instances of ClassName in memory: 1

Soooo, here are my questions:

1) I know that just one extra instance is no big deal, but it bugs me that it's there... Can I load the class without creating it, or even destroy it somehow?

2) This causes problems when I want to auto load a class that has parameters in it's constructor, as I don't see a way to pass parameters in the Autoload... To resolve i did the following, but I don't like it much...

<?php if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class ClassName {
    public function  __construct($params=NULL) {
        if (!$params) return;
        //Rest of the constructor...

Is there a better way to autoload classes with parameters?

Ok, that's enough for now, thanks for your time!

Messages In This Thread
Can I load a library class without creating an instance of it? [SOLVED] - by El Forum - 07-25-2011, 07:22 AM

Theme © iAndrew 2016 - Forum software by © MyBB