-
Notifications
You must be signed in to change notification settings - Fork 791
Rewrite type section #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite type section #1726
Conversation
49a0464
to
bceb622
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with the documentation format so some of these might be wrong (e.g. I'm not sure if <type>
does something special).
language/types/declarations.xml
Outdated
value returned must be an &instanceof; the same class as the one | ||
the method is called in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value returned must be an &instanceof; the same class as the one | |
the method is called in. | |
value returned must be an &instanceof; the same class as the class of the object itself. |
Maybe the wording can be improved. But it has nothing to do with the caller, you can call said method outside of the given class hierarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the current wording that already exist. I'll think about improving it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can clarify with an example. "For example, an object Cat
inheriting Animal::getClone(): static
must return a Cat
, not just any Animal
(which would be the behavior of self
)."
Actually, that is supposed to create a link, but IIRC this is broken for quite a while now. Anyhow, could use XML entities instead. |
language/types/declarations.xml
Outdated
|
||
<warning> | ||
<para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about moving this to a list instead of a table. The table seems more readable to me for this, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the list as it allows nesting, also the table currently has no real grouping (and I don't know how to make it sensible) + a version release column which acts a bit weirdly live (might be some CSS issue)
language/types/declarations.xml
Outdated
<warning> | ||
<para> | ||
The list of base types is: | ||
<itemizedlist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether it's a list or stays as a table, each item should deep-link to the spot in the page where it's described. (Same for the other index lists in the page.)
Glancing over the section... I barely understand why this page is what it is and where it is. Shouldn't a description of different types come way earlier in the section? It's basically at the end now. Is the whole Types section due for an overhaul? |
Yes, probably, I wrote this page back when PHP 8.0 got released as the information about type declarations where scattered in loads of different places. So this was done to centralise it. |
php/phd#33 is meant to fix it, might need to go back to it |
6327d5b
to
9875534
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me we're mixing "types" and "type declarations", but we should better not. I think it's better to move much of what we have on the type declaration page to the introduction page, and to have only info about type declarations on the former (general info about type declarations, and the special declaration types like self
).
2e877f4
to
f0ca282
Compare
I don't really think I've addressed your comment @cmb69, but I'm still really blanking on how to break the relevant bits away, as I wrote it all from writing a type declaration perspective :-/ |
8dd73ca
to
c31cdf1
Compare
Okay, I've spent some time again rewritting this, and would love to get your comments and opinions on this. |
c31cdf1
to
3b02d68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This is quite something.
|
||
<sect3 xml:id="language.types.declarations.base.scalar"> | ||
<title>Scalar types</title> | ||
<warning> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange now; previously, there was a list of types, and the section referred to that ("above"). Now, there is only a warning without any general info about the "scalar types". The situation is similar for other sections in this file. Maybe we should link to the general descriptions at the beginning of each <sect3>
, or have some general info at the beginning of this page.
</example> | ||
|
||
<example> | ||
<title>Catching <classname>TypeError</classname></title> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for removing this! We should probably clarify elsewhere that catching Error
s is usually not supposed to be done.
To incorporate typing features added in PHP 8.2.0 and also (hopefully) future proof for additionnal additions
Introduce individual pages for all types Add a type system page which describes the type system in agnostic way to userland type declaration Convert the userland type declaration page to just document neessary info related to writing such declarations Move strict_type coercion handling to the type juggling page
Co-authored-by: Christoph M. Becker <[email protected]>
577f6a6
to
d5b5c62
Compare
d5b5c62
to
a2f1915
Compare
Okay, I've only performed limited changes to try to address all the review comments. Hopefully this is now good to land and be stabbed by the pitchforks of translators. @saundefined @mumumu what are your opinions of this as the translators of the 2 other main up to date languages? |
LGTM, thanks! |
@Girgias Personally, I don't have a problem with it. This PR change is not mahoosive than I expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Co-authored-by: Christoph M. Becker <[email protected]>
I found some typo line 48 Thank you. |
This commit rewrites the whole type section to (hopefully) be better structured and future proof for further additions to the type system. * Each type now gets their individual page instead of being shoved in the type declaration page. * A type system page is added which describes PHP's type system, regardless if it is possible to declare the type in userland or not. Therefore, the type declaration page only has information related to writing type declarations in userland. * The description of strict_type and the type coercion is moved into the type juggling page. * Remove outdated information in string implementation section * Add paragraph about using non string in string context can throw Co-authored-by: Christoph M. Becker <[email protected]>
To incorporate typing features added in PHP 8.2.0 and also (hopefully) future proof for additional additions.
This is still a bit WIP as I haven't added DNF types but I already wanted to get some eyes on it to gather some opinions.
I've taken a bit of inspiration from the Rust manual: https://doc.rust-lang.org/reference/types.html