Jump to content

Constructor question


TomTees

Recommended Posts

That is a java/C++/C# instruction, though I haven't yet seen it in use within the context of a php class. Typically the __construct() method is just defined on it's own (except when a class is extended I believe (though I am most likely wrong there - don't use that too much myself))

 

__construct(args...)

 

That is used to pass things into the class at runtime - that's how I have always understood it to be anyway, then within that method, you would use it to setup controller or error array's, at least that's normally how I do it ;-p

 

Rw

When you define functions you don't need to specify the return type; in fact, you can't, but for functions that come bundled with PHP the manual tells you the return types. PHP isn't a strict-typed language, but types do still exist. Just because you can't define explicity what a function must return, it doesn't mean that it doesn't return a variable of some type.

 

For example, consider the following function:

 

function some_function() {
    return "This is a string!";
}

 

There is obviously no explicit definition for the return type of that function, and such a declaration isn't possible in PHP, but that function will always return a string type.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.