-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate direct access to static trait members
Static trait members may only be accessed through a class in which the trait is used, not directly on the trait. A complication here is that we should not store static methods/properties for which a deprecation is triggered in a cache slot. As the check for this is simple and cheap, I'm handling this in the cache slot population code in the VM. The alternative would be to pass the cache slot down into the fetching code. Part of https://wiki.php.net/rfc/deprecations_php_8_1.
- Loading branch information
Showing
7 changed files
with
138 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--TEST-- | ||
Direct access to static trait members is deprecated | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
public static $foo; | ||
public static function foo() { | ||
echo "Foo\n"; | ||
} | ||
public static function __callStatic($name, $args) { | ||
echo "CallStatic($name)\n"; | ||
} | ||
} | ||
|
||
class C { | ||
use T; | ||
} | ||
|
||
function test() { | ||
T::$foo = 42; | ||
var_dump(T::$foo); | ||
T::foo(); | ||
T::bar(); | ||
echo "\n"; | ||
} | ||
|
||
// Call twice to test cache slot behavior. | ||
test(); | ||
test(); | ||
|
||
C::$foo = 42; | ||
var_dump(C::$foo); | ||
C::foo(); | ||
C::bar(); | ||
|
||
?> | ||
--EXPECTF-- | ||
Deprecated: Accessing static trait property T::$foo is deprecated, it should only be accessed on a class using the trait in %s on line %d | ||
|
||
Deprecated: Accessing static trait property T::$foo is deprecated, it should only be accessed on a class using the trait in %s on line %d | ||
int(42) | ||
|
||
Deprecated: Calling static trait method T::foo is deprecated, it should only be called on a class using the trait in %s on line %d | ||
Foo | ||
|
||
Deprecated: Calling static trait method T::bar is deprecated, it should only be called on a class using the trait in %s on line %d | ||
CallStatic(bar) | ||
|
||
|
||
Deprecated: Accessing static trait property T::$foo is deprecated, it should only be accessed on a class using the trait in %s on line %d | ||
|
||
Deprecated: Accessing static trait property T::$foo is deprecated, it should only be accessed on a class using the trait in %s on line %d | ||
int(42) | ||
|
||
Deprecated: Calling static trait method T::foo is deprecated, it should only be called on a class using the trait in %s on line %d | ||
Foo | ||
|
||
Deprecated: Calling static trait method T::bar is deprecated, it should only be called on a class using the trait in %s on line %d | ||
CallStatic(bar) | ||
|
||
int(42) | ||
Foo | ||
CallStatic(bar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters