Skip to content

Conversation

@apermo
Copy link
Contributor

@apermo apermo commented Sep 10, 2024

This fixes #143

Also taken care of @jrfnl 's comment on slack that autoloading only applies to classes and not to functions or constants.

Fixed: require/import => require/include
Per @jrfnl's suggestion, made clear that autoloading only applies to classes.
Fixed missing space.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks for catching that typo @apermo! I've left a small suggestion inline. Let me know what you think.


[info]
Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load whatever is being imported. You'll either need to set up autoloading or load the file containing the class/function/constant using a `require/import` statement, for the imported constructs to be loaded when used.
Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require` or `include`.
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
Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include` statement, for the imported classes to be loaded when used. Autoloading is only applicable to classes; for functions and constants, you must always use `require` or `include`.
Note that, unless you have implemented [autoloading](https://www.php.net/manual/en/language.oop5.autoload.php), the `use` statement won't automatically load referenced classes. You'll either need to set up autoloading or load the file containing the class using a `require/include[_once]` statement. Autoloading is only applicable to classes; for functions and constants, you must always use `require[_once]` or `include[_once]`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely like the added [_once] in the new sentence. I'll already apply that second part.

I am personally unsure about the require/include[_once].

I personally read it as "'require/includestatement", and due to that "statement" I included the optional_once` for both.
If you want to make it clear, I personally would suggest:

[...] or load the file containing the class using require[_once] or include[_once]. [...]

Imho that improves readability. Otherwise I personally would keep require/include.

Your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jrfnl I've added the before mentioned change. And changed order to alphabetical (first include then require) this matches the paragraph on "Writing include/require statements" in lines 81-83 of the same file.

Let me know your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

The order was intentional - require should generally be preferred over include, which is why it was mentioned first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jrfnl I agree with that point. What do you think about adjusting the other appearance of include/require to require/include, to match the same idea?

Copy link
Member

Choose a reason for hiding this comment

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

I'd need to look at the complete doc to be sure (on the road now, so can't look), but in principle, I'd be open to such a change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jrfnl I've updated the order, and I've added a subsentence to the documentation in the upper paragraph. My experience showed that include statements can result in silent malfunctions, which are a pain to track down. If you disagree adding this, I'm absolutely fine to omit that.

Applied suggestion from code review by @jrfnl
Further code review feedback.
Changed order to alphabetikal order: include, require. To be consistent with Lines 81-83 (Writing include/require statements) and
Switched from alphabetical order, to recommendation order.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

@apermo Sorry for the slow turn-around. I've had another critical look and I think this still needs more tweaking, largely because the PR is trying to do more than just fix the issue you reported.

@apermo
Copy link
Contributor Author

apermo commented Mar 26, 2025

@jrfnl I've missed your reply and just taken care of your comments.
Applied the suggestion, removed the "silent error" suggestion.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks for making those update @apermo ! This is looking good now. Just one nitpick left.

@apermo
Copy link
Contributor Author

apermo commented Mar 27, 2025

Resolved @jrfnl

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks @apermo ! This now looks good to go 👍🏻

@dingo-d @GaryJones Want to do a final review & do the honours ? (squash-merge please!)

Copy link
Member

@dingo-d dingo-d left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍🏼

@dingo-d dingo-d merged commit 1ba96d0 into WordPress:master Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

require/import vs require/include in PHP Coding Standards Documentation.

3 participants