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 invocable'; 41$fn = Closure::fromCallable(new PublicInvocable); 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 protected 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--EXPECT-- 100Access public static function OK 101Access public static function with different case OK 102Access public static function with colon scheme OK 103Access public instance method of object OK 104Access public instance method of parent object through parent:: OK 105Function that exists OK 106Function that exists with different spelling OK 107Closure is already a closure OK 108Class with public invocable OK 109Instance return private method as callable OK 110Instance return private static method as callable OK 111Instance return protected static method as callable OK 112Subclass closure over parent class protected method OK 113Subclass closure over parent class static protected method OK 114Access public instance method of parent object through "parent::" OK 115Access public instance method of self object through "self::" OK 116Access public instance method of parent object through "self::" to parent method OK 117Access protected instance method of parent object through "self::" to parent method OK 118MagicCall __call instance method __call,nonExistentMethod, OK 119MagicCall __callStatic static method __callStatic,nonExistentMethod, OK 120