Skip to content
Advertisement

Tag: constructor

Static class initializer in PHP

I have an helper class with some static functions. All the functions in the class require a ‘heavy’ initialization function to run once (as if it were a constructor). Is there a good practice for achieving this? The only thing I thought of was calling an init function, and breaking its flow if it has already run once (using a

Best way to do multiple constructors in PHP

You can’t put two __construct functions with unique argument signatures in a PHP class. I’d like to do this: What is the best way to do this in PHP? Answer I’d probably do something like this: Then if i want a Student where i know the ID: Or if i have an array of the db row: Technically you’re not

What is the function __construct used for?

I have been noticing __construct a lot with classes. I did a little reading and surfing the web, but I couldn’t find an explanation I could understand. I am just beginning with OOP. I was wondering if someone could give me a general idea of what it is, and then a simple example of how it is used with PHP?

Advertisement