Skip to content

Fix bad Pure attributes #1730

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Fix bad Pure attributes #1730

wants to merge 6 commits into from

Conversation

cs278
Copy link
Contributor

@cs278 cs278 commented Apr 10, 2025

This PR is based on my interpretation of the documentation on the attribute that Pure(true) means a function:

  • Does not have any side effects on external state or the supplied parameters
  • and the result depends on some external state outside of the supplied parameters.

This contradicts with the interpretation in #1724 by @zonuexe which was accepted:

Added the missing #[Pure(true)] attribute to some functions that have side effects [emphasis mine] but whose return value is important.

The reasoning for each change is documented in the commit messages.

As such it reverts some of the changes made in that PR. If my interpretation is wrong then reject this, but please improve the documentation.

cs278 added 6 commits April 10, 2025 22:01
These functions all trigger autoloading which may have the effect
of definining one or more new symbols. Note this does not apply
to `function_exists()` as there is no function autoloading.
Neither of these functions depend on any external state.
Both functions have the side effect of ending the current output
buffer. Whilst the latter also writes to the output stream.
As this function takes a callable it should not be marked as pure,
this appears to be the convention based on all the other array user
intersect/diff functions.
@@ -609,7 +605,7 @@ function get_class_vars(string $class): array {}
* for the specified <i>object</i> in scope. If a property have
* not been assigned a value, it will be returned with a null value.
*/
#[Pure(true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this change is also incorrect since function actually depends on global state. The function depends on the structure of the class from which the object was instantiated. If the class definition changes (e.g., due to autoloading), the result can change. Also if string property names or values are affected by locale settings (e.g., setlocale()), it might affect the output. Please correct me if I'm wrong

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.

2 participants