That's a type declaration. From the manual:
Type declarations allow functions to require that parameters are of a
certain type at call time. If the given value is of the incorrect
type, then an error is generated: in PHP 5, this will be a recoverable
fatal error, while PHP 7 will throw a
TypeError exception.
To specify a type declaration, the type name should be added before
the parameter name. The declaration can be made to accept NULL
values if the default value of the parameter is set to NULL.
So, if we didn't specify the type declaration for $db in your code, we could instantiate the class with a null argument, which would cause the object's $db parameter to be set to null:
$object = new ClassName( null );
By specifying that the single parameter for the constructor must be of type Database, PHP will throw an error (or exception in PHP 7) if we pass it anything other than a Database object. For example:
$object = new ClassName( null ); // Throws an error / exception
$db = new Database();
$object = new ClassName( $db ); // Performs as expected.
In this particular case, Database is an object type defined by the framework/library you're working with (i.e. class Database { ... }).
Date, for example? Errors would be thrown that methods / properties do not exist.Databasekeyword before the variable name. How do I search about this convention so I can learn more about it?$dbshould be. You're aware that variables in PHP can have different types, right?dband it still works.