1--TEST-- 2Closure $this unbinding deprecation 3--FILE-- 4<?php 5 6class Test { 7 public function method() { 8 echo "instance scoped, non-static, \$this used\n"; 9 $fn = function() { 10 var_dump($this); 11 }; 12 $fn->bindTo(null); 13 echo "instance scoped, static, \$this used\n"; 14 $fn = static function() { 15 var_dump($this); 16 }; 17 $fn->bindTo(null); 18 echo "instance scoped, non-static, \$this not used\n"; 19 $fn = function() { 20 var_dump($notThis); 21 }; 22 $fn->bindTo(null); 23 } 24 25 public static function staticMethod() { 26 echo "static scoped, non-static, \$this used\n"; 27 $fn = function() { 28 var_dump($this); 29 }; 30 $fn->bindTo(null); 31 echo "static scoped, static, \$this used\n"; 32 $fn = static function() { 33 var_dump($this); 34 }; 35 $fn->bindTo(null); 36 echo "static scoped, static, \$this not used\n"; 37 $fn = function() { 38 var_dump($notThis); 39 }; 40 $fn->bindTo(null); 41 } 42} 43 44(new Test)->method(); 45Test::staticMethod(); 46 47?> 48--EXPECTF-- 49instance scoped, non-static, $this used 50 51Warning: Cannot unbind $this of closure using $this in %s on line %d 52instance scoped, static, $this used 53instance scoped, non-static, $this not used 54static scoped, non-static, $this used 55static scoped, static, $this used 56static scoped, static, $this not used 57