Why is stdClass a type hint in many functions since Moodle 2.3?

Re: Why is stdClass a type hint in many functions since Moodle 2.3?

by Onno Schuit -
Number of replies: 0

Michael,

I'd consider extending my own class from stdClass a workaround too. wink

As for making it clear in your API what kind of argument your function expects, well, stdClass does not convey any information to the "user" of your API. It's the most generic class you can have in php.

Unfortunately, you can't just enforce that the function argument be an object (versus, say, an integer) without specifying exactly which class you want as an argument.

My proposal would be to abandon stdClass as a type hint, and use clear variable names to provide a hint. E.g. $user is an object, $userid is an integer.