Skip to content
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

[RFC] Function Autoloading #4

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

withinboredom
Copy link
Contributor

@withinboredom withinboredom commented Aug 18, 2024

I've moved this from the records branch to track it separately.

Summary by CodeRabbit

  • New Features

    • Introduced function autoloading in PHP, allowing undefined functions to be automatically loaded when called.
    • Updated the autoloading mechanism to support both class and function registration, enhancing flexibility.
    • Enhanced function_exists to provide control over autoloading behavior when checking for function presence.
  • Documentation

    • Added a new RFC detailing the function autoloading process and its implications for PHP development.

@withinboredom withinboredom self-assigned this Aug 18, 2024
Copy link

coderabbitai bot commented Aug 18, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The new RFC introduces a function autoloading mechanism in PHP, allowing undefined functions to be automatically loaded when invoked. This enhancement aligns function autoloading with existing class autoloading features, adding constants and modifying key SPL functions. It provides developers with improved flexibility in managing function definitions across namespaces while ensuring backward compatibility with existing functionality.

Changes

Files Change Summary
ext/spl/spl.c Updated spl_autoload_register and spl_autoload_call to handle an additional parameter for function type.
ext/standard/function.c Enhanced function_exists to include a boolean option for invoking autoloading for undefined functions.

Poem

🐇 In the land of PHP, oh what a delight,
Functions now dance in the soft moonlight.
With autoloading magic, they spring into play,
Making coding easier, come join the fray!
Hops of joy for each line we write,
In this whimsical world, everything feels right! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Review details

Configuration used: .coderabbit.yml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between d13508f and 32d7763.

Files ignored due to path filters (1)
  • published/function-autoloading.ptxt is excluded by !**/*.ptxt
Files selected for processing (1)
  • drafts/function-autoloading.md (1 hunks)
Additional context used
Path-based instructions (1)
drafts/function-autoloading.md (1)

Pattern drafts/*.md: These are PHP RFC's to change the PHP language. Do not just consider the grammar of the text, but consider how it might change the language. For example, if a new feature is being added, consider how it might be used, and propose better ideas if you have them.

LanguageTool
drafts/function-autoloading.md

[style] ~6-~6: ‘Under Discussion’ might be wordy. Consider a shorter alternative.
Context: ...ers, [email protected] * Status: Under Discussion (or Accepted or Declined) * First Publi...

(EN_WORDINESS_PREMIUM_UNDER_DISCUSSION)


[uncategorized] ~48-~48: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ..., strlen()), 2. is not defined locally 3. and an autoloader is registered with the SP...

(COMMA_COMPOUND_SENTENCE_2)


[typographical] ~113-~113: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...r will be called if the function is not defined, otherwise, it will not be called. ## Backward Inc...

(THUS_SENTENCE)


[style] ~143-~143: Consider replacing this phrase with the adverb “similarly” to avoid wordiness.
Context: ...stants and stream wrappers can be added in a similar fashion. ## Proposed Voting Choices <doodle t...

(IN_A_X_MANNER)

Markdownlint
drafts/function-autoloading.md

165-165: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


166-166: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


167-167: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


147-147: Element: doodle
Inline HTML

(MD033, no-inline-html)


5-5: null
Bare URL used

(MD034, no-bare-urls)

Additional comments not posted (2)
drafts/function-autoloading.md (2)

9-12: Clear Introduction.

The introduction provides a concise and clear context for the RFC, aligning it with past discussions and existing class autoloading.


61-75: Effective Example.

The example effectively demonstrates the proposed function autoloading mechanism.

Comment on lines 137 to 145
## Open Issues

To be determined.

## Future Scope

Potentially, constants and stream wrappers can be added in a similar fashion.

## Proposed Voting Choices
Copy link

Choose a reason for hiding this comment

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

Keep sections updated.

Ensure that open issues and future scope sections are updated as discussions and developments progress.

Would you like assistance in tracking these sections for updates?

Tools
LanguageTool

[style] ~143-~143: Consider replacing this phrase with the adverb “similarly” to avoid wordiness.
Context: ...stants and stream wrappers can be added in a similar fashion. ## Proposed Voting Choices <doodle t...

(IN_A_X_MANNER)

Comment on lines 145 to 154
## Proposed Voting Choices

<doodle title="Implement Function Autoloading v4, as described" auth="withinboredom" voteType="single" closed="true" closeon="2022-01-01T00:00:00Z">
* Yes
* No
</doodle>

## Patches and Tests

Not yet.
Copy link

Choose a reason for hiding this comment

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

Voting Choices Clear.

The proposed voting choices are clear and well-structured.

Reminder: Provide patches.

Patches and tests are not yet provided. Consider prioritizing this to facilitate implementation.

Would you like help in drafting patches or tests?

Tools
Markdownlint

147-147: Element: doodle
Inline HTML

(MD033, no-inline-html)

Comment on lines 156 to 169
## Implementation

After the project is implemented, this section should contain - the
version(s) it was merged into - a link to the git commit(s) - a link to
the PHP manual entry for the feature - a link to the language
specification section (if any)

## References

- [autofunc](https://wiki.php.net/rfc/autofunc): This heavily influenced this RFC. (declined in 2011)
- [function_autoloading](https://wiki.php.net/rfc/function_autoloading): This RFC was declined in 2011.
- [function_autoloading_v2](https://wiki.php.net/rfc/function_autoloading2): This RFC was declined in 2012.

Thank you for all of those that contributed to the discussions back then. I hope that this RFC will be successful.
Copy link

Choose a reason for hiding this comment

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

References Well-Documented.

The references to past RFCs provide valuable context and are well-documented.

Keep Implementation Section Updated.

Ensure the implementation section is updated with relevant details once the project progresses.

Would you like assistance in tracking implementation updates?

Tools
Markdownlint

165-165: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


166-166: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


167-167: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)

Comment on lines 171 to 173
## Rejected Features

Keep this updated with features that were discussed on the mail lists.
Copy link

Choose a reason for hiding this comment

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

Keep Rejected Features Updated.

Ensure the rejected features section is updated with features that are discussed and not included.

Would you like assistance in tracking rejected features?

Comment on lines 125 to 131
8.5 or later.

## RFC Impact

### To Opcache

To be determined.
Copy link

Choose a reason for hiding this comment

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

Clarify Opcache impact.

The impact on Opcache is currently unspecified. Consider updating this section with any available insights or plans.

+ Update: Analyze potential Opcache changes or optimizations needed for function autoloading.

Committable suggestion was skipped due to low confidence.

Comment on lines 78 to 121
Performance-wise, this should have minimal impact on existing codebases as there is no default function autoloader.

For codebases that want to take advantage of function autoloading,
it may be desirable to stick with FQNs for functions and/or employ caches and other techniques where possible.

### spl_autoload

`spl_autoload`'s second argument will be updated to accept `int|string|null` as the second parameter so that it can use
the new callback signature.
If the second parameter is an int, and it is not `SPL_AUTOLOAD_CLASS`,
an `Error` is thrown: 'Default autoloader can only load classes.'

There will not be a default function autoloader.

### spl_autoload_call

The `spl_autoload_call` function will be modified to accept a second parameter of one,
(but not both) of the new constants,
with the default value set to SPL_AUTOLOAD_CLASS.
The name of the first parameter will be changed to `$name` to reflect that it can be a class or function name.

```php
spl_autoload_call('\Some\func', SPL_AUTOLOAD_FUNCTION); // Calls the function autoloader
spl_autoload_call('\Some\func'); // Calls the class autoloader
spl_autoload_call('Some\func', SPL_AUTOLOAD_CLASS); // Calls the class autoloader
spl_autoload_call('Some\func'); // Calls the class autoloader
spl_autoload_call('func', SPL_AUTOLOAD_FUNCTION | SPL_AUTOLOAD_CLASS); // Error: Cannot autoload multiple types
```

If the user wants to call multiple autoloaders, they can do so manually.

### function_exists

The `function_exists` function will be updated to include a boolean option (`$autoload`) as the second parameter,
which will default to `true`.
If set to `true`, the function autoloader will be called if the function is not defined, otherwise, it will not be
called.

## Backward Incompatible Changes

### Mismatched arguments

If an autoloader was registered that can accept more than one argument,
it may fail or perform unexpected behavior when it receives a second argument of `SPL_AUTOLOAD_CLASS`.
Copy link

Choose a reason for hiding this comment

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

Expand on performance and compatibility.

Consider providing more detailed analysis or examples regarding performance impact and handling mismatched arguments.

+ Example: If an autoloader expects a single argument, ensure it can handle the second argument gracefully.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Performance-wise, this should have minimal impact on existing codebases as there is no default function autoloader.
For codebases that want to take advantage of function autoloading,
it may be desirable to stick with FQNs for functions and/or employ caches and other techniques where possible.
### spl_autoload
`spl_autoload`'s second argument will be updated to accept `int|string|null` as the second parameter so that it can use
the new callback signature.
If the second parameter is an int, and it is not `SPL_AUTOLOAD_CLASS`,
an `Error` is thrown: 'Default autoloader can only load classes.'
There will not be a default function autoloader.
### spl_autoload_call
The `spl_autoload_call` function will be modified to accept a second parameter of one,
(but not both) of the new constants,
with the default value set to SPL_AUTOLOAD_CLASS.
The name of the first parameter will be changed to `$name` to reflect that it can be a class or function name.
```php
spl_autoload_call('\Some\func', SPL_AUTOLOAD_FUNCTION); // Calls the function autoloader
spl_autoload_call('\Some\func'); // Calls the class autoloader
spl_autoload_call('Some\func', SPL_AUTOLOAD_CLASS); // Calls the class autoloader
spl_autoload_call('Some\func'); // Calls the class autoloader
spl_autoload_call('func', SPL_AUTOLOAD_FUNCTION | SPL_AUTOLOAD_CLASS); // Error: Cannot autoload multiple types
```
If the user wants to call multiple autoloaders, they can do so manually.
### function_exists
The `function_exists` function will be updated to include a boolean option (`$autoload`) as the second parameter,
which will default to `true`.
If set to `true`, the function autoloader will be called if the function is not defined, otherwise, it will not be
called.
## Backward Incompatible Changes
### Mismatched arguments
If an autoloader was registered that can accept more than one argument,
it may fail or perform unexpected behavior when it receives a second argument of `SPL_AUTOLOAD_CLASS`.
Performance-wise, this should have minimal impact on existing codebases as there is no default function autoloader.
For codebases that want to take advantage of function autoloading,
it may be desirable to stick with FQNs for functions and/or employ caches and other techniques where possible.
### spl_autoload
`spl_autoload`'s second argument will be updated to accept `int|string|null` as the second parameter so that it can use
the new callback signature.
If the second parameter is an int, and it is not `SPL_AUTOLOAD_CLASS`,
an `Error` is thrown: 'Default autoloader can only load classes.'
There will not be a default function autoloader.
### spl_autoload_call
The `spl_autoload_call` function will be modified to accept a second parameter of one,
(but not both) of the new constants,
with the default value set to SPL_AUTOLOAD_CLASS.
The name of the first parameter will be changed to `$name` to reflect that it can be a class or function name.
```php
spl_autoload_call('\Some\func', SPL_AUTOLOAD_FUNCTION); // Calls the function autoloader
spl_autoload_call('\Some\func'); // Calls the class autoloader
spl_autoload_call('Some\func', SPL_AUTOLOAD_CLASS); // Calls the class autoloader
spl_autoload_call('Some\func'); // Calls the class autoloader
spl_autoload_call('func', SPL_AUTOLOAD_FUNCTION | SPL_AUTOLOAD_CLASS); // Error: Cannot autoload multiple types
```
If the user wants to call multiple autoloaders, they can do so manually.
### function_exists
The `function_exists` function will be updated to include a boolean option (`$autoload`) as the second parameter,
which will default to `true`.
If set to `true`, the function autoloader will be called if the function is not defined, otherwise, it will not be
called.
## Backward Incompatible Changes
### Mismatched arguments
If an autoloader was registered that can accept more than one argument,
it may fail or perform unexpected behavior when it receives a second argument of `SPL_AUTOLOAD_CLASS`.
+ Example: If an autoloader expects a single argument, ensure it can handle the second argument gracefully.
Tools
LanguageTool

[typographical] ~113-~113: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...r will be called if the function is not defined, otherwise, it will not be called. ## Backward Inc...

(THUS_SENTENCE)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Review details

Configuration used: .coderabbit.yml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 32d7763 and 1a57a5c.

Files ignored due to path filters (1)
  • published/function-autoloading.ptxt is excluded by !**/*.ptxt
Files selected for processing (1)
  • drafts/function-autoloading.md (1 hunks)
Additional context used
Path-based instructions (1)
drafts/function-autoloading.md (1)

Pattern drafts/*.md: These are PHP RFC's to change the PHP language. Do not just consider the grammar of the text, but consider how it might change the language. For example, if a new feature is being added, consider how it might be used, and propose better ideas if you have them.

LanguageTool
drafts/function-autoloading.md

[style] ~6-~6: ‘Under Discussion’ might be wordy. Consider a shorter alternative.
Context: ...ers, [email protected] * Status: Under Discussion (or Accepted or Declined) * First Publi...

(EN_WORDINESS_PREMIUM_UNDER_DISCUSSION)


[uncategorized] ~48-~48: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ..., strlen()), 2. is not defined locally 3. and an autoloader is registered with the SP...

(COMMA_COMPOUND_SENTENCE_2)


[uncategorized] ~78-~78: Possible missing comma found.
Context: ... should have minimal impact on existing codebases as there is no default function autoloa...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~113-~113: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...r will be called if the function is not defined, otherwise, it will not be called. ## Backward Inc...

(THUS_SENTENCE)


[style] ~143-~143: Consider replacing this phrase with the adverb “similarly” to avoid wordiness.
Context: ...stants and stream wrappers can be added in a similar fashion. ## Proposed Voting Choices <!-- markd...

(IN_A_X_MANNER)

Markdownlint
drafts/function-autoloading.md

166-166: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


167-167: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


168-168: Expected: asterisk; Actual: dash
Unordered list style

(MD004, ul-style)


147-147: Element: doodle
Inline HTML

(MD033, no-inline-html)


5-5: null
Bare URL used

(MD034, no-bare-urls)

Additional comments not posted (9)
drafts/function-autoloading.md (9)

9-13: Introduction is clear and well-structured.

The introduction effectively sets the context for the proposal by referencing past discussions on function autoloading.


61-76: Example is clear and effective.

The code snippet provides a clear demonstration of the proposed function autoloading mechanism.


83-90: spl_autoload section is clear.

The proposed changes to spl_autoload are well-explained and align with the overall proposal.


92-108: spl_autoload_call section is clear and well-illustrated.

The modifications to spl_autoload_call are clearly explained with examples.


116-122: Backward Incompatible Changes section is clear.

The section adequately addresses potential issues with mismatched arguments in autoloaders.


137-145: Keep sections updated.

Ensure that open issues and future scope sections are updated as discussions and developments progress.

Tools
LanguageTool

[style] ~143-~143: Consider replacing this phrase with the adverb “similarly” to avoid wordiness.
Context: ...stants and stream wrappers can be added in a similar fashion. ## Proposed Voting Choices <!-- markd...

(IN_A_X_MANNER)


157-163: Keep Implementation Section Updated.

Ensure the implementation section is updated with relevant details once the project progresses.


172-174: Keep Rejected Features Updated.

Ensure the rejected features section is updated with features that are discussed and not included.


5-5: Avoid using bare URLs.

Consider formatting the URL as a hyperlink for better readability.

- * First Published at: <http://wiki.php.net/rfc/function_autoloading4>
+ * First Published at: [PHP RFC](http://wiki.php.net/rfc/function_autoloading4)

Likely invalid or redundant comment.

Tools
Markdownlint

5-5: null
Bare URL used

(MD034, no-bare-urls)

Comment on lines +147 to +151
<doodle title="Implement Function Autoloading v4, as described" auth="withinboredom" voteType="single" closed="true" closeon="2022-01-01T00:00:00Z">
* Yes
* No
</doodle>
<!-- markdownlint-disable MD037 -->
Copy link

Choose a reason for hiding this comment

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

Avoid inline HTML for voting choices.

Consider using Markdown alternatives to inline HTML for better compatibility and readability.

- <doodle title="Implement Function Autoloading v4, as described" auth="withinboredom" voteType="single" closed="true" closeon="2022-01-01T00:00:00Z">
+ <!-- Voting choices: Implement Function Autoloading v4, as described -->
+ * Yes
+ * No
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<doodle title="Implement Function Autoloading v4, as described" auth="withinboredom" voteType="single" closed="true" closeon="2022-01-01T00:00:00Z">
* Yes
* No
</doodle>
<!-- markdownlint-disable MD037 -->
<!-- Voting choices: Implement Function Autoloading v4, as described -->
* Yes
* No
<!-- markdownlint-disable MD037 -->
Tools
Markdownlint

147-147: Element: doodle
Inline HTML

(MD033, no-inline-html)

drafts/function-autoloading.md Show resolved Hide resolved
Comment on lines 129 to 131
### To Opcache

Update: Analyze potential Opcache changes or optimizations needed for function autoloading.
Copy link

Choose a reason for hiding this comment

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

Clarify Opcache impact.

The impact on Opcache is currently unspecified. Consider updating this section with any available insights or plans.

+ Update: Analyze potential Opcache changes or optimizations needed for function autoloading.

Committable suggestion was skipped due to low confidence.

Comment on lines 78 to 82
Performance-wise, this should have minimal impact on existing codebases as there is no default function autoloader.

For codebases that want to take advantage of function autoloading,
it may be desirable to stick with FQNs for functions and/or employ caches and other techniques where possible.

Copy link

Choose a reason for hiding this comment

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

Expand on performance analysis.

Consider providing more detailed analysis or examples regarding the performance impact.

+ Example: If an autoloader expects a single argument, ensure it can handle the second argument gracefully.

Committable suggestion was skipped due to low confidence.

Tools
LanguageTool

[uncategorized] ~78-~78: Possible missing comma found.
Context: ... should have minimal impact on existing codebases as there is no default function autoloa...

(AI_HYDRA_LEO_MISSING_COMMA)

Comment on lines +109 to +114
### function_exists

The `function_exists` function will be updated to include a boolean option (`$autoload`) as the second parameter,
which will default to `true`.
If set to `true`, the function autoloader will be called if the function is not defined, otherwise, it will not be
called.
Copy link

Choose a reason for hiding this comment

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

Clarify sentence structure.

Consider revising the sentence to separate the clauses correctly.

- If set to `true`, the function autoloader will be called if the function is not defined, otherwise, it will not be called.
+ If set to `true`, the function autoloader will be called if the function is not defined. Otherwise, it will not be called.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### function_exists
The `function_exists` function will be updated to include a boolean option (`$autoload`) as the second parameter,
which will default to `true`.
If set to `true`, the function autoloader will be called if the function is not defined, otherwise, it will not be
called.
### function_exists
The `function_exists` function will be updated to include a boolean option (`$autoload`) as the second parameter,
which will default to `true`.
If set to `true`, the function autoloader will be called if the function is not defined. Otherwise, it will not be
called.
Tools
LanguageTool

[typographical] ~113-~113: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...r will be called if the function is not defined, otherwise, it will not be called. ## Backward Inc...

(THUS_SENTENCE)

Comment on lines 28 to 35
1. Add two new constants to spl: SPL_AUTOLOAD_CLASS, SPL_AUTOLOAD_FUNCTION.
2. Add a fourth optional parameter for spl_autoload_register, with a default value of SPL_AUTOLOAD_CLASS.
3. The type for the missing token should also be passed to the $autoload_function callback as a second param. (e.g.,
SPL_AUTOLOAD_CLASS for classes, SPL_AUTOLOAD_FUNCTION for functions)
4. Change the current class autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_CLASS types.
5. Add the function autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_FUNCTION types.

There won’t be any changes to the current autoloading mechanism when it comes to classes.
Copy link

Choose a reason for hiding this comment

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

Clarify the proposal with examples.

Including examples for changes to spl_autoload_register and new constants would improve clarity.

+ Example: `spl_autoload_register($autoload_function, false, false, SPL_AUTOLOAD_FUNCTION);`
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
1. Add two new constants to spl: SPL_AUTOLOAD_CLASS, SPL_AUTOLOAD_FUNCTION.
2. Add a fourth optional parameter for spl_autoload_register, with a default value of SPL_AUTOLOAD_CLASS.
3. The type for the missing token should also be passed to the $autoload_function callback as a second param. (e.g.,
SPL_AUTOLOAD_CLASS for classes, SPL_AUTOLOAD_FUNCTION for functions)
4. Change the current class autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_CLASS types.
5. Add the function autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_FUNCTION types.
There won’t be any changes to the current autoloading mechanism when it comes to classes.
1. Add two new constants to spl: SPL_AUTOLOAD_CLASS, SPL_AUTOLOAD_FUNCTION.
2. Add a fourth optional parameter for spl_autoload_register, with a default value of SPL_AUTOLOAD_CLASS.
3. The type for the missing token should also be passed to the $autoload_function callback as a second param. (e.g.,
SPL_AUTOLOAD_CLASS for classes, SPL_AUTOLOAD_FUNCTION for functions)
4. Change the current class autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_CLASS types.
5. Add the function autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_FUNCTION types.
There won’t be any changes to the current autoloading mechanism when it comes to classes.
Example: `spl_autoload_register($autoload_function, false, false, SPL_AUTOLOAD_FUNCTION);`

Comment on lines 16 to 25
Before getting into the details,
there are a few terms worth acknowledging so that the proposal can be easily discussed without getting confused:

1. **Defined function**: A function that the engine has knowledge of, such as in a previously included/required file.
2. **Undefined function**: A function that the engine does not have knowledge of.
3. **Function autoloading**: The process of loading a function that is not defined.
4. **Written function**: A function that exists in a file that the engine may or may not have knowledge of.
5. **Local scope**: The current namespace
6. **Global scope**: The global namespace (`\`)

Copy link

Choose a reason for hiding this comment

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

Enhance understanding with examples for key terms.

Providing examples for the defined terms can help clarify their meanings.

+ For example, a **Defined function** might be one included via `require 'file.php';`.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Before getting into the details,
there are a few terms worth acknowledging so that the proposal can be easily discussed without getting confused:
1. **Defined function**: A function that the engine has knowledge of, such as in a previously included/required file.
2. **Undefined function**: A function that the engine does not have knowledge of.
3. **Function autoloading**: The process of loading a function that is not defined.
4. **Written function**: A function that exists in a file that the engine may or may not have knowledge of.
5. **Local scope**: The current namespace
6. **Global scope**: The global namespace (`\`)
Before getting into the details,
there are a few terms worth acknowledging so that the proposal can be easily discussed without getting confused:
1. **Defined function**: A function that the engine has knowledge of, such as in a previously included/required file.
+ For example, a **Defined function** might be one included via `require 'file.php';`.
2. **Undefined function**: A function that the engine does not have knowledge of.
3. **Function autoloading**: The process of loading a function that is not defined.
4. **Written function**: A function that exists in a file that the engine may or may not have knowledge of.
5. **Local scope**: The current namespace
6. **Global scope**: The global namespace (`\`)

@withinboredom
Copy link
Contributor Author

@coderabbitai pause

Copy link

coderabbitai bot commented Aug 18, 2024

Actions performed

Reviews paused.

@withinboredom withinboredom changed the title Add function autoloading [RFC] Function Autoloading Aug 19, 2024
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.

1 participant