1--TEST-- 2Testing Closure::fromCallable() functionality: Basic 3--FILE-- 4<?php 5 6include('closure_from_callable.inc'); 7 8echo 'Access public static function'; 9$fn = Closure::fromCallable(['Foo', 'publicStaticFunction']); 10echo $fn(" OK".PHP_EOL); 11 12echo 'Access public static function with different case'; 13$fn = Closure::fromCallable(['fOo', 'publicStaticfUNCTION']); 14echo $fn(" OK".PHP_EOL); 15 16echo 'Access public static function with colon scheme'; 17$fn = Closure::fromCallable('Foo::publicStaticFunction'); 18echo $fn(" OK".PHP_EOL); 19 20echo 'Access public instance method of object'; 21$fn = Closure::fromCallable([new Foo, 'publicInstanceFunc']); 22echo $fn(" OK".PHP_EOL); 23 24echo 'Access public instance method of parent object through parent:: '; 25$fn = Closure::fromCallable([new Foo, 'publicInstanceFunc']); 26echo $fn(" OK".PHP_EOL); 27 28echo 'Function that exists'; 29$fn = Closure::fromCallable('bar'); 30echo $fn(" OK".PHP_EOL); 31 32echo 'Function that exists with different spelling'; 33$fn = Closure::fromCallable('BAR'); 34echo $fn(" OK".PHP_EOL); 35 36echo 'Closure is already a closure'; 37$fn = Closure::fromCallable($closure); 38echo $fn(" OK".PHP_EOL); 39 40echo 'Class with public invokable'; 41$fn = Closure::fromCallable(new PublicInvokable); 42echo $fn(" OK".PHP_EOL); 43 44echo "Instance return private method as callable"; 45$foo = new Foo; 46$fn = $foo->closePrivateValid(); 47echo $fn(" OK".PHP_EOL); 48 49echo "Instance return private static method as callable"; 50$foo = new Foo; 51$fn = $foo->closePrivateStatic(); 52echo $fn(" OK".PHP_EOL); 53 54echo 'Instance return protected static method as callable'; 55$subFoo = new SubFoo; 56$fn = $subFoo->closeProtectedStaticMethod(); 57echo $fn(" OK".PHP_EOL); 58 59echo 'Subclass closure over parent class protected method'; 60$subFoo = new SubFoo; 61$fn = $subFoo->closeProtectedValid(); 62echo $fn(" OK".PHP_EOL); 63 64echo 'Subclass closure over parent class static protected method'; 65$subFoo = new SubFoo; 66$fn = $subFoo->closeProtectedStaticMethod(); 67echo $fn(" OK".PHP_EOL); 68 69echo 'Access public instance method of parent object through "parent::" '; 70$subFoo = new SubFoo; 71$fn = $subFoo->getParentPublicInstanceMethod(); 72echo $fn(" OK".PHP_EOL); 73 74echo 'Access public instance method of self object through "self::" '; 75$foo = new Foo; 76$fn = $foo->getSelfColonPublicInstanceMethod(); 77echo $fn(" OK".PHP_EOL); 78 79echo 'Access public instance method of parent object through "self::" to parent method'; 80$foo = new SubFoo; 81$fn = $foo->getSelfColonParentPublicInstanceMethod(); 82echo $fn(" OK".PHP_EOL); 83 84echo 'Access proteced instance method of parent object through "self::" to parent method'; 85$foo = new SubFoo; 86$fn = $foo->getSelfColonParentProtectedInstanceMethod(); 87echo $fn(" OK".PHP_EOL); 88 89echo 'MagicCall __call instance method '; 90$fn = Closure::fromCallable([new MagicCall, 'nonExistentMethod']); 91echo $fn(" OK".PHP_EOL); 92 93echo 'MagicCall __callStatic static method '; 94$fn = Closure::fromCallable(['MagicCall', 'nonExistentMethod']); 95echo $fn(" OK".PHP_EOL); 96 97 98?> 99===DONE=== 100--EXPECT-- 101Access public static function OK 102Access public static function with different case OK 103Access public static function with colon scheme OK 104Access public instance method of object OK 105Access public instance method of parent object through parent:: OK 106Function that exists OK 107Function that exists with different spelling OK 108Closure is already a closure OK 109Class with public invokable OK 110Instance return private method as callable OK 111Instance return private static method as callable OK 112Instance return protected static method as callable OK 113Subclass closure over parent class protected method OK 114Subclass closure over parent class static protected method OK 115Access public instance method of parent object through "parent::" OK 116Access public instance method of self object through "self::" OK 117Access public instance method of parent object through "self::" to parent method OK 118Access proteced instance method of parent object through "self::" to parent method OK 119MagicCall __call instance method __call,nonExistentMethod, OK 120MagicCall __callStatic static method __callStatic,nonExistentMethod, OK 121===DONE=== 122