Hi guys,

I've made a class with a lot of functions, and for the 99% of the time i need the __construct functi.
How can i call the class without the __construct ?

class Test
{
    public function __construct()
    {
        echo "bla";
    }
}

$test = new Test();

What I want is when I call the new $test->blabla($test); the construct should not be invoked.

Recommended Answers

All 4 Replies

__construct is the function that gets called when an object instance of the class is created. Even if you remove it, it will be called, so make sure you do not put any output in it. The only way around it is creating a static class.

That was my solution as well, created a static class after all.
Tought that I can skip the __construct :)

there is a php function called reflection class as shown here, but never tried it.

there is a php function called reflection class as shown here, but never tried it.

Tried this class, it works but still the __construct is passing trough :)
As pritaeas said, the simplest workaround is to build a separate static class :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.