I propose that the 'object' type be prohibited via a PHPCS sniff in docblocks, when used with annotations like @param, @return, @property etc. Rationale:
- A common mistake is to confuse object with stdClass. However, the former accepts *any* object (i.e. anything that is not scalar and not array), while the latter only accepts what people may call "objects", i.e. stdClass instances
- object as a documented type, when it's not used for stdClass, is very unhelpful, because it doesn't convey any information about the parameter. Knowing that it's not a scalar will not save me from reading the method body to figure out the type
- In particular, the docblock should always explicitly mention what types are expected by the method. Again, object is not really different from a complete lack of documentation.
- However, object can still be allowed as a typehint, for situations like the following, assuming that a vague typehint is better than no typehint. Note, I wouldn't encourage this practice: it might make more sense to specialize the method, or split it in two, or create a base interface. But I think it shouldn't be forbidden either.
/** * @param TypeA|TypeB $foo */ function foo ( object $foo ) { }
As always, the warning can be suppressed in "special cases" where using object is legit. I don't have any examples for this. OTOH, codesearch will give you many examples where object is used in place of stdClass.
A caveat: make sure that PHPCS won't complain about typehint not matching docblock in the example above.