mirror of
https://github.com/php/php-src.git
synced 2026-03-30 20:22:36 +02:00
Only deprecate unbinding of $this from a closure if $this is syntactically used within the closure. This is desired to support Laravel's macro system, see laravel/framework#29482. This should still allow us to implement the performance improvements we're interested in for PHP 8, without breaking existing use-cases.
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
--TEST--
|
|
Closure $this unbinding deprecation
|
|
--FILE--
|
|
<?php
|
|
|
|
class Test {
|
|
public function method() {
|
|
echo "instance scoped, non-static, \$this used\n";
|
|
$fn = function() {
|
|
var_dump($this);
|
|
};
|
|
$fn->bindTo(null);
|
|
echo "instance scoped, static, \$this used\n";
|
|
$fn = static function() {
|
|
var_dump($this);
|
|
};
|
|
$fn->bindTo(null);
|
|
echo "instance scoped, non-static, \$this not used\n";
|
|
$fn = function() {
|
|
var_dump($notThis);
|
|
};
|
|
$fn->bindTo(null);
|
|
}
|
|
|
|
public static function staticMethod() {
|
|
echo "static scoped, non-static, \$this used\n";
|
|
$fn = function() {
|
|
var_dump($this);
|
|
};
|
|
$fn->bindTo(null);
|
|
echo "static scoped, static, \$this used\n";
|
|
$fn = static function() {
|
|
var_dump($this);
|
|
};
|
|
$fn->bindTo(null);
|
|
echo "static scoped, static, \$this not used\n";
|
|
$fn = function() {
|
|
var_dump($notThis);
|
|
};
|
|
$fn->bindTo(null);
|
|
}
|
|
}
|
|
|
|
(new Test)->method();
|
|
Test::staticMethod();
|
|
|
|
?>
|
|
--EXPECTF--
|
|
instance scoped, non-static, $this used
|
|
|
|
Deprecated: Unbinding $this of closure is deprecated in %s on line %d
|
|
instance scoped, static, $this used
|
|
instance scoped, non-static, $this not used
|
|
static scoped, non-static, $this used
|
|
static scoped, static, $this used
|
|
static scoped, static, $this not used
|