1<?php 2 3function bar($param1) 4{ 5 return $param1; 6} 7 8 9$closure = function($param1) { 10 return $param1; 11}; 12 13function test($fn) 14{ 15 static $count = 0; 16 $input = "foo".$count; 17 $count++; 18 19 $output = $fn($input); 20 return $input === $output; 21} 22 23class Foo 24{ 25 public static function publicStaticFunction($param1) 26 { 27 return $param1; 28 } 29 30 private static function privateStaticFunction($param1) 31 { 32 return $param1; 33 } 34 35 protected static function protectedStaticFunction($param1) 36 { 37 return $param1; 38 } 39 40 private function privateInstanceFunc($param1) 41 { 42 return $param1; 43 } 44 45 protected function protectedInstanceFunc($param1) 46 { 47 return $param1; 48 } 49 50 51 public function publicInstanceFunc($param1) 52 { 53 return $param1; 54 } 55 56 public function closePrivateValid() 57 { 58 return Closure::fromCallable([$this, 'privateInstanceFunc']); 59 } 60 61 public function closePrivateStatic() 62 { 63 return Closure::fromCallable([__CLASS__, 'privateStaticFunction']); 64 } 65 66 public function bar($param1) 67 { 68 echo "this is bar\n"; 69 } 70 71 public function getCallable() 72 { 73 return Closure::fromCallable([$this, 'publicInstanceFunc']); 74 } 75 76 public function getSelfPublicInstance() 77 { 78 return Closure::fromCallable([$this, 'publicInstanceFunc']); 79 } 80 81 public function getSelfColonPublicInstanceMethod() 82 { 83 return Closure::fromCallable('self::publicInstanceFunc'); 84 } 85} 86 87 88 89class SubFoo extends Foo { 90 91 public function closePrivateStaticInvalid() 92 { 93 return Closure::fromCallable([__CLASS__, 'privateStaticFunction']); 94 } 95 96 97 public function closePrivateInvalid() 98 { 99 return Closure::fromCallable([$this, 'privateInstanceFunc']); 100 } 101 102 public function closeProtectedStaticMethod() 103 { 104 return Closure::fromCallable([__CLASS__, 'protectedStaticFunction']); 105 } 106 107 public function closeProtectedValid() 108 { 109 return Closure::fromCallable([$this, 'protectedInstanceFunc']); 110 } 111 112 public function getParentPublicInstanceMethod() 113 { 114 return Closure::fromCallable('parent::publicInstanceFunc'); 115 } 116 117 public function getSelfColonParentPublicInstanceMethod() 118 { 119 return Closure::fromCallable('self::publicInstanceFunc'); 120 } 121 122 123 public function getSelfColonParentProtectedInstanceMethod() 124 { 125 return Closure::fromCallable('self::protectedInstanceFunc'); 126 } 127 128 public function getSelfColonParentPrivateInstanceMethod() 129 { 130 return Closure::fromCallable('self::privateInstanceFunc'); 131 } 132} 133 134 135class MagicCall 136{ 137 public function __call($name, $arguments) 138 { 139 $info = ['__call']; 140 $info[] = $name; 141 $info = array_merge($info, $arguments); 142 return implode(',', $info); 143 } 144 145 public static function __callStatic($name, $arguments) 146 { 147 $info = ['__callStatic']; 148 $info[] = $name; 149 $info = array_merge($info, $arguments); 150 return implode(',', $info); 151 } 152} 153 154 155 156class PublicInvocable 157{ 158 public function __invoke($param1) 159 { 160 return $param1; 161 } 162} 163 164 165function functionAccessProtected() 166{ 167 $foo = new Foo; 168 169 return Closure::fromCallable([$foo, 'protectedStaticFunction']); 170} 171 172function functionAccessPrivate() 173{ 174 $foo = new Foo; 175 176 return Closure::fromCallable([$foo, 'privateStaticFunction']); 177} 178 179 180function functionAccessMethodDoesntExist() 181{ 182 $foo = new Foo; 183 184 return Closure::fromCallable([$foo, 'thisDoesNotExist']); 185} 186 187?> 188