Skip to content

Remove $this from incompatible context #1026

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
wants to merge 1 commit into from
Closed

Conversation

nikic
Copy link
Member

@nikic nikic commented Jan 26, 2015

  • If we can detect at compile-time that a function uses $this,
    then ZEND_ACC_ALLOW_STATIC flag will not be set.
  • A static call (either without object or object from an incompatible
    class) to a non-static method without ZEND_ACC_ALLOW_STATIC will
    generate a fatal error.
  • If static calls are allowed an E_DEPRECATED will be generated.
  • In this case $this will be NULL. This makes sure that even
    obscured (varvar) usages of $this will not be able to access an
    object from an incompatible context.

 * If we can detect at compile-time that a function uses $this,
   then ZEND_ACC_ALLOW_STATIC flag will not be set.
 * A static call (either without object or object from an incompatible
   class) to a non-static method without ZEND_ACC_ALLOW_STATIC will
   generate a fatal error.
 * If static calls are allowed an E_DEPRECATED will be generated.
 * In this case $this will be NULL. This makes sure that even
   obscured (varvar) usages of $this will not be able to access an
   object from an incompatible context.
@smalyshev smalyshev added the RFC label Feb 1, 2015
@mbeccati
Copy link
Contributor

PEAR and other classes historically allowed some methods to be called both ways and $this was used to check whether or not the method was called statically and adjust the behaviour accordingly, e.g. https://github.com/pear/pear-core/blob/stable/PEAR.php#L652

Adding the static modifier removes $this altogether, whereas this PR triggers a fatal error. Using the varvar trick allows the code to work, raising an E_DEPRECATED (vs E_STRICT in 5.6).

@nikic
Copy link
Member Author

nikic commented Feb 27, 2015

Closing as this won't be merged in this form.

@nikic nikic closed this Feb 27, 2015
@cweiske
Copy link
Contributor

cweiske commented Mar 3, 2015

We've already fixed most of this cases in pear-core branch "incompatible context" - https://github.com/pear/pear-core/tree/incompatible-context

So this would not be a problem for us at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants