Conversation
99d4382 to
7e27c03
Compare
Until php#10098 default constructors were sometimes documented, sometimes omitted. The above PR made adding documentation for constructor of all non-abstract classes required. However, this is not desired when such a class inherits a constructor from its parent. The current PR fixes the behavior the following way: - documents inherited constructors (along with destructors) - makes it possible to generate/replace the methodsynopsis of implicit default constructors which don't have a stub counterpart
7e27c03 to
e609d1d
Compare
|
I've just realized that reflection still not recognizes these constructors (e.g. I think this should be addressed in PHP 8.3 so that each class has to either declare or inherit a constructor (this would only be enforced by gen_stub.php). PHP 8.2 could still emulate the default constructors as per this PR. What do you think? |
I'm not sure, it makes sense because the main reason why a constructor is not implemented is that it doesn't take any argument, because it is pointless. And documenting it when it doesn't exist seems like a mistake in the same way as changing the internal behaviour because you can hit this exact same issue in userland: https://3v4l.org/mOTEF |
Hmm, this is an issue. If we document |
I disagree with the "they do not really exist" and the "it would probably be better to not document them" parts: all classes have at least the default constructor which doesn't take any arguments and which doesn't do anything (apart from instantiating the class). That's why it makes sense to document them in my opinion (even the ones which result in an exception to clarify that they shouldn't be used). What reflection really provides information about is whether a class has (declares or inherits) a custom constructor implementation. I agree that it's debatable to change this, but any way, from a user perspective, constructors can be invoked on any classes, no matter what reflection says.
Yeah, I forgot to mention this in my previous reply, but the above point stays. :) |
I don't think this ("default constructor") is a valid model for PHP (contrary to some other languages). Instead we should distinguish between object creation and construction (i.e. calling the constructor). While the PHP manual doesn't seem to be particularly clear on this, the language specification is:
Ignoring reflection (or reflection like features), and while it is generally not recommended to explicitly call the constructor, that is possible, but only if a Of course, one may argue that there is a default constructor (if not explicitly defined or inherited) which is called, but can't be called explicitly and is not "visible" to reflection, but in my opinion, this complicates what is actually going on, and as such is not a helpful model for userland developers (it is more complex for internals due to |
Thank you for highlighting this fact, I completely forgot to check it (even though I did check other magic methods...). You persuaded me that documenting non-existent constructors is a wrong approach, so I did a few followups:
|
Girgias
left a comment
There was a problem hiding this comment.
I still don't really understand how gen_stub works, so trusting you on that.
cmb69
left a comment
There was a problem hiding this comment.
Thank you! Looks good to me (as far as I can tell).
Until #10098 default constructors were sometimes documented, sometimes omitted.
The above PR made adding documentation for constructor of all non-abstract classes required. However, this is not desired when such a class inherits a constructor from its parent. The current PR fixes the behavior the following way:makes it possible to generate/replace the methodsynopsis of implicit default constructors which don't have a stub