Skip to content

Make class_alias() work with internal classes #9826

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

Closed
nicolas-grekas opened this issue Oct 25, 2022 · 1 comment
Closed

Make class_alias() work with internal classes #9826

nicolas-grekas opened this issue Oct 25, 2022 · 1 comment

Comments

@nicolas-grekas
Copy link
Contributor

Description

I was reminded today that class_alias() doesn't work with internal classes.

I have a use case where a class can be defined either by userland or by an optional extension, and I'd ideally need to alias it. Right now, I have to create a proxy class instead of an alias, and proxy classes are tedious to write+maintain.

Could this limitation be removed?

@nikic
Copy link
Member

nikic commented Nov 6, 2022

I've run into this as well. I think from a technical perspective, the main complication is that a) we can't increment the refcount of an internal class during a request and b) we will have an internal class appear in the region for userland classes in the class table. Class aliases already use a special flag in the class table to distinguish them, so it would be possible to not increment the refcount and skip the aliases entirely for destruction purposes.

nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 1, 2023
We can't increase the refcount of internal classes during request time.
We fix this issue by not increasing refcount for internal classes upon
creating an alias and taking this into account during the destruction.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 1, 2023
We can't increase the refcount of internal classes during request time.
We fix this issue by not increasing refcount for internal classes upon
creating an alias and taking this into account during the destruction.
To differentiate between the lifetimes, a new
IS_INTERNAL_CLASS_REQUEST_ALIAS_PTR internal type is added.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 2, 2023
We can't increase the refcount of internal classes during request time.
We fix this issue by not increasing refcount for internal classes upon
creating an alias and taking this into account during the destruction.
To differentiate between the lifetimes, a new
IS_INTERNAL_CLASS_REQUEST_ALIAS_PTR internal type is added.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 5, 2023
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 5, 2023
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 6, 2023
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 17, 2023
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 21, 2023
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
iluuu1994 pushed a commit that referenced this issue Feb 22, 2023
)

We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants