TomTees Posted November 7, 2010 Share Posted November 7, 2010 void __construct ([ mixed $args [, $... ]] ) What is the "void" in the above code? (It looks like Java?!) TomTees Quote Link to comment https://forums.phpfreaks.com/topic/218043-constructor-question/ Share on other sites More sharing options...
rwwd Posted November 7, 2010 Share Posted November 7, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/218043-constructor-question/#findComment-1131506 Share on other sites More sharing options...
Alex Posted November 7, 2010 Share Posted November 7, 2010 That's the return type for the method. The constructor doesn't return anything, so it's void. Quote Link to comment https://forums.phpfreaks.com/topic/218043-constructor-question/#findComment-1131516 Share on other sites More sharing options...
TomTees Posted November 7, 2010 Author Share Posted November 7, 2010 That's the return type for the method. The constructor doesn't return anything, so it's void. I thought PHP didn't use variable typing and such? Am I supposed to include "void" in my PHP Constructors? TomTees Quote Link to comment https://forums.phpfreaks.com/topic/218043-constructor-question/#findComment-1131518 Share on other sites More sharing options...
Alex Posted November 7, 2010 Share Posted November 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/218043-constructor-question/#findComment-1131521 Share on other sites More sharing options...
TomTees Posted November 7, 2010 Author Share Posted November 7, 2010 Okay, thanks! TomTees Quote Link to comment https://forums.phpfreaks.com/topic/218043-constructor-question/#findComment-1131524 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.