9/11/2023 0 Comments Php maker template![]() ![]() In some situations the PHPDoc tag can be used instead. ![]() Only objects of classes extending Exception will be accepted and returned by this function. You can also limit which types can be used in place of the type variable with an upper bound using the of keyword: /** The type variable name can be anything, as long as you don’t use an existing class name. Consider a function that returns the same type it accepts: /** ![]() In PHPDocs we annotate them with the tag. Other languages that have generics also use this term. These rules are defined using type variables. They offer generating infinite number of signatures for functions and methods based on rules developers can define themselves. It’s not enough information to keep the code type-safe. finds and returns an entity object based on $className If you have a function that returns different types based on argument types passed when calling the function, you’d have to resort to returning a union type, or a more general type like object or mixed: function findEntity ( string $className, int $id ) : ? object So we declare that the function accepts an argument of a specific type, and also returns a specific type: /** When we’re declaring a function, we’re used to attach a single signature to it. Also check out practical examples in the Generics By Examples article. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |