So here is the deal. I want to call a class and pass a value to it so it can be used inside that class in all the various functions ect. ect. How would I go about doing that?
Thanks, Sam
So here is the deal. I want to call a class and pass a value to it so it can be used inside that class in all the various functions ect. ect. How would I go about doing that?
Thanks, Sam
The concept is called "constructor".
As the other answers point out, you should use the unified constructor syntax (
__construct()
) as of PHP 5. Here is an example of how this looks like:Notice - There are so-called old style constructors that you might run into in legacy code. They look like this:
This form is officially deprecated as of PHP 7 and you should no longer use it for new code.