1--TEST-- 2Closure 044: Scope/bounding combination invariants; non static closures 3--FILE-- 4<?php 5/* A non-static closure has a bound instance if it has a scope 6 * and doesn't have an instance if it has no scope */ 7 8$nonstaticUnscoped = function () { var_dump(isset(A::$priv)); var_dump(isset($this)); }; 9 10class A { 11 private static $priv = 7; 12 function getClosure() { 13 return function() { var_dump(isset(A::$priv)); var_dump(isset($this)); }; 14 } 15} 16 17$a = new A(); 18$nonstaticScoped = $a->getClosure(); 19 20echo "Before binding", "\n"; 21$nonstaticUnscoped(); echo "\n"; 22$nonstaticScoped(); echo "\n"; 23 24echo "After binding, null scope, no instance", "\n"; 25$d = $nonstaticUnscoped->bindTo(null, null); $d(); echo "\n"; 26$d = $nonstaticScoped->bindTo(null, null); $d(); echo "\n"; 27 28echo "After binding, null scope, with instance", "\n"; 29$d = $nonstaticUnscoped->bindTo(new A, null); $d(); echo "\n"; 30$d = $nonstaticScoped->bindTo(new A, null); $d(); echo "\n"; 31 32echo "After binding, with scope, no instance", "\n"; 33$d = $nonstaticUnscoped->bindTo(null, 'A'); $d(); echo "\n"; 34$d = $nonstaticScoped->bindTo(null, 'A'); $d(); echo "\n"; 35 36echo "After binding, with scope, with instance", "\n"; 37$d = $nonstaticUnscoped->bindTo(new A, 'A'); $d(); echo "\n"; 38$d = $nonstaticScoped->bindTo(new A, 'A'); $d(); echo "\n"; 39 40echo "Done.\n"; 41--EXPECTF-- 42Before binding 43bool(false) 44bool(false) 45 46bool(true) 47bool(true) 48 49After binding, null scope, no instance 50bool(false) 51bool(false) 52 53 54Deprecated: Unbinding $this of closure is deprecated in %s on line %d 55bool(false) 56bool(false) 57 58After binding, null scope, with instance 59bool(false) 60bool(true) 61 62bool(false) 63bool(true) 64 65After binding, with scope, no instance 66bool(true) 67bool(false) 68 69 70Deprecated: Unbinding $this of closure is deprecated in %s on line %d 71bool(true) 72bool(false) 73 74After binding, with scope, with instance 75bool(true) 76bool(true) 77 78bool(true) 79bool(true) 80 81Done. 82