Skip to content

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

Merged
merged 15 commits into from
Nov 30, 2022
Merged

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jul 28, 2022

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

@Girgias Girgias requested review from Crell, iluuu1994 and cmb69 July 28, 2022 20:35
@Girgias Girgias force-pushed the rewrite-type-declaration-page branch from 49a0464 to bceb622 Compare July 28, 2022 20:40
Copy link
Member

@iluuu1994 iluuu1994 left a 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).

Comment on lines 194 to 198
value returned must be an &instanceof; the same class as the one
the method is called in.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member Author

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

Copy link
Member

@iluuu1994 iluuu1994 Jul 30, 2022

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)."

@cmb69
Copy link
Member

cmb69 commented Jul 29, 2022

I'm not sure if <type> does something special

Actually, that is supposed to create a link, but IIRC this is broken for quite a while now. Anyhow, could use XML entities instead.


<warning>
<para>
Copy link
Contributor

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?

Copy link
Member Author

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)

<warning>
<para>
The list of base types is:
<itemizedlist>
Copy link
Contributor

@Crell Crell Jul 31, 2022

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.)

@Crell
Copy link
Contributor

Crell commented Jul 31, 2022

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?

@Girgias
Copy link
Member Author

Girgias commented Jul 31, 2022

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.

@Girgias
Copy link
Member Author

Girgias commented Jul 31, 2022

I'm not sure if <type> does something special

Actually, that is supposed to create a link, but IIRC this is broken for quite a while now. Anyhow, could use XML entities instead.

php/phd#33 is meant to fix it, might need to go back to it

@Girgias Girgias added this to the PHP 8.2 milestone Sep 26, 2022
@Girgias Girgias force-pushed the rewrite-type-declaration-page branch 2 times, most recently from 6327d5b to 9875534 Compare September 26, 2022 10:58
Copy link
Member

@cmb69 cmb69 left a 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).

@Girgias Girgias force-pushed the rewrite-type-declaration-page branch 2 times, most recently from 2e877f4 to f0ca282 Compare September 27, 2022 13:18
@Girgias
Copy link
Member Author

Girgias commented Sep 27, 2022

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 :-/

@Girgias Girgias changed the title Rewrite type declaration page Rewrite type section Sep 27, 2022
@Girgias Girgias force-pushed the rewrite-type-declaration-page branch 2 times, most recently from 8dd73ca to c31cdf1 Compare November 7, 2022 04:10
@Girgias
Copy link
Member Author

Girgias commented Nov 7, 2022

Okay, I've spent some time again rewritting this, and would love to get your comments and opinions on this.

@iluuu1994 iluuu1994 self-requested a review November 7, 2022 07:03
@Girgias Girgias force-pushed the rewrite-type-declaration-page branch from c31cdf1 to 3b02d68 Compare November 10, 2022 13:46
Copy link
Member

@cmb69 cmb69 left a 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>
Copy link
Member

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>
Copy link
Member

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 Errors is usually not supposed to be done.

@cmb69 cmb69 added the mahoosive-change Grab a cup of coffee and dive in. label Nov 22, 2022
Girgias and others added 13 commits November 23, 2022 15:44
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]>
@Girgias Girgias force-pushed the rewrite-type-declaration-page branch from 577f6a6 to d5b5c62 Compare November 23, 2022 16:56
@Girgias Girgias force-pushed the rewrite-type-declaration-page branch from d5b5c62 to a2f1915 Compare November 23, 2022 16:59
@Girgias
Copy link
Member Author

Girgias commented Nov 23, 2022

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?

@saundefined
Copy link
Member

@saundefined @mumumu what are your opinions of this as the translators of the 2 other main up to date languages?

LGTM, thanks!

@mumumu
Copy link
Member

mumumu commented Nov 24, 2022

@Girgias Personally, I don't have a problem with it. This PR change is not mahoosive than I expected.

Copy link
Member

@cmb69 cmb69 left a 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]>
@Girgias Girgias merged commit 161dde4 into php:master Nov 30, 2022
@Girgias Girgias deleted the rewrite-type-declaration-page branch November 30, 2022 15:39
@kitrio
Copy link

kitrio commented Nov 30, 2022

I found some typo
File language/types/type-system.xml
line 48 <simpara><type>float</type> string</simpara>
it seems like typo
because line 45 already write float <simpara><type>float</type> type</simpara>

line 48 <simpara><type>string</type> type</simpara>
Is this right?

Thank you.

@cmb69
Copy link
Member

cmb69 commented Nov 30, 2022

Thanks for reporting, @kitrio! Should be fixed with 23cda46.

claudepache pushed a commit to claudepache/php-doc-en that referenced this pull request Jun 1, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mahoosive-change Grab a cup of coffee and dive in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants